0

我想我做了不该做的事。我尝试使用 stash,但认为我应该分支,并在那里做。无论如何,这些是我所做的命令:

git branch test     # created my test branch
git checkout test   # moved to my test branch
git status          # showed that the files were still changed.
git stash           # testing stash
git stash list      # showed that the stash was there
git status          # showed that the files were still changed?
git diff            # showed that the differences were only file permissions.
git stash apply     # Tried to get back my changes. States:
                    #   error: Your local changes to the following files would be overwritten by merge:
                    #   ...
                    #   Please, commit your changes or stash them before you can merge.
                    #   Aborting
git commit file -m "- committing test code that doesn't work."
git status          # Shows that it's clean

所以,我认为问题在于分支和签出会擦除我的更改而不是保留它们。那是对的吗?如果没有,我可以取回我的更改吗?

4

1 回答 1

0
git stash apply     # Tried to get back my changes. States:
                    #   error: Your local changes to the following files would be overwritten by merge:
                    #   ...
                    #   Please, commit your changes or stash them before you can merge.
                    #   Aborting
git commit file -m "- committing test code that doesn't work."
git status          # Shows that it's clean

这表明未应用存储(尝试被中止,因为您有可能被存储覆盖的本地更改)。

最后两个命令提交了工作目录中存在的更改(至少,我假设他们这样做了——您已经git add从命令运行列表中删除了该步骤)。您永远不会重新应用存储,因此它应该仍然存在。

检查git stash list说什么。

从评论中git stash liststash@{0}: WIP on test: 0581365 Added。这意味着您有一个隐藏的提交,您可以应用它(例如git stash apply)。

于 2013-11-13T06:02:54.207 回答