Git:无法撤消本地更改(错误:路径...未合并)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3021161/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git: can't undo local changes (error: path ... is unmerged)
提问by mklhmnn
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 andmodified? What should I do?
两个部分中的相同文件,新的和修改的?我该怎么办?
回答by Igor Zevaka
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
回答by Steffi
This worked perfectly for me:
这对我来说非常有效:
$ git reset -- foo/bar.txt
$ git checkout foo/bar.txt
回答by Joe Hyde
git checkout origin/[branch] .
git status
// Note dot (.) at the end. And all will be good
// 注意末尾的点 (.)。一切都会好的
回答by zed_0xff
git checkout foo/bar.txt
did you tried that? (without a HEAD keyword)
你试过吗?(没有 HEAD 关键字)
I usually revert my changes this way.
我通常以这种方式还原我的更改。