使用git stash命令后文件状态丢失

3
echo Hello. > a.txt
git add .
echo Bye. >> a.txt
git status -s
>>> AM

我们可以看到状态是AM,但是在执行以下操作时:
git stash
git stash pop
git status -s
>>> A

状态为 A。 为什么会丢失 M 状态?


2
“git stash apply” 或者 “git stash apply --index”(而不是 “git stash pop”)哪个更好用? - VonC
1个回答

2
这是预期的行为。如果想按照您的期望进行重构(保留A&M),请使用:
git stash pop --index

文档描述:

git-stash(1):

If the --index option is used, then tries to reinstate not only the working
tree’s hanges, but also the index’s ones. However, this can fail, when you have
conflicts (which are stored in the index, where you therefore can no longer apply
the changes as they were originally).

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接