others - git :不能撤销本地修改(error:path…is unmerged)

工作树状态


$ git status foo/bar.txt
# On branch master
# Unmerged paths:
# (use"git reset HEAD <file>..." to unstage)
# (use"git add/rm <file>..." as appropriate to mark resolution)
#
# deleted by us: foo/bar.txt
#
no changes added to commit (use"git add" and/or"git commit -a")

文件foo/bar.txt存在,并且我希望将它重新设置为"unchanged state",然后('复制到:


$ git checkout HEAD foo/bar.txt
error: path 'foo/bar.txt' is unmerged
$ git reset HEAD foo/bar.txt
Unstaged changes after reset:
M foo/bar.txt


$ git status foo/bar.txt
# On branch master
# Changes to be committed:
# (use"git reset HEAD <file>..." to unstage)
#
# new file: foo/bar.txt
#
# Changed but not updated:
# (use"git add <file>..." to update what will be committed)
# (use"git checkout -- <file>..." to discard changes in working directory)
#
# modified: foo/bar.txt
#

时间:

你做了错误的选择,您应该先进行重置,先取消暂存文件,然后签出,再恢复本地更改。

尝试这个:


$ git reset foo/bar.txt
$ git checkout foo/bar.txt

...