本文翻译自:Git: can't undo local changes (error: path … is unmerged)
I have following working tree state 我有以下工作树状态
$ 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")
File foo/bar.txt
is there and I want to get it to the "unchanged state" again (similar to 'svn revert'): 文件foo/bar.txt
在那里,我想再次将它变为“未更改的状态”(类似于'svn revert'):
$ 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
Now it is getting confusing: 现在它变得令人困惑:
$ 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
#
The same file in both sections, new and modified? 两个部分中的相同文件,新增和修改? What should I do? 我该怎么办?
#1楼
参考:https://stackoom.com/question/CfwP/Git-无法撤消本地更改-错误-路径-已取消合并
#2楼
git checkout origin/[branch] .
git status
// Note dot (.) at the end. //注意末尾的点(。)。 And all will be good 一切都会好的
#3楼
This worked perfectly for me: 这对我很有用:
$ git reset -- foo/bar.txt
$ git checkout foo/bar.txt
#4楼
git checkout foo/bar.txt
did you tried that? 你试过那个吗? (without a HEAD keyword) (没有HEAD关键字)
I usually revert my changes this way. 我通常会以这种方式恢复我的更改。
#5楼
You did it the wrong way around. 你做错了。 You are meant to reset first, to unstage the file, then checkout, to revert local changes. 您应首先重置,取消暂存文件,然后结帐,以恢复本地更改。
Try this: 试试这个:
$ git reset foo/bar.txt
$ git checkout foo/bar.txt
#6楼
我发现git stash对于所有'脏'状态的时间处理非常有用。