git mv file1 file2
git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# renamed: file1 -> file2
git stash
git stash pop
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: file2
#
# Changes not staged for commit:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: file1
如您所见,git 在 stash / pop 之后失去了重命名的关系。有没有办法恢复这种关系,或者让 stash 知道文件被移动了?我经常隐藏以查看我的系统状态是什么样的预更改,但是让它失去重命名关系对我来说是个问题。除了删除新文件,再次执行 git mv 并替换新文件的内容之外,我不知道如何修复它。