git - git stash 命令后文件状态丢失

标签 git git-stash

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 状态丢失了?

最佳答案

这是预期的行为。要按预期重建它(保存 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).

关于git - git stash 命令后文件状态丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13915098/

相关文章:

git - 我想推送到一个不是 master 的分支。那就是我所做的

git - 如何在 MacOS 上为 git.path 配置 VS Code?

git - ssh -T git@github.com : You've successfully authenticated | sudo git pull: Permission denied (publickey)

git - 撤销意外的 git stash pop

Git Stash Apply on Master 而不是 Local branch

git - 无法使用 git 存储库创建网站并从 Team Foundation 服务发布

Git 存储未提交的文件

Git 无法撤销修改过的文件

git - 如何重命名 git stash?

ios - 使用两个 Apple 开发者帐户使用 git 协作处理 Xcode 项目