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知道文件已经移动了? 我经常使用stash查看更改前的系统状态,但它失去重命名关系对我来说是个问题。除了删除新文件,再次执行git mv并替换新文件内容,我不知道如何解决这个问题。