当前位置:   article > 正文

Git:无法撤消本地更改(错误:路径...已取消合并)_error: path' is unmerged

error: path' is unmerged

本文翻译自:Git: can't undo local changes (error: path … is unmerged)

I have following working tree state 我有以下工作树状态

  1. $ git status foo/bar.txt
  2. # On branch master
  3. # Unmerged paths:
  4. # (use "git reset HEAD <file>..." to unstage)
  5. # (use "git add/rm <file>..." as appropriate to mark resolution)
  6. #
  7. # deleted by us: foo/bar.txt
  8. #
  9. 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'):

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

Now it is getting confusing: 现在它变得令人困惑:

  1. $ git status foo/bar.txt
  2. # On branch master
  3. # Changes to be committed:
  4. # (use "git reset HEAD <file>..." to unstage)
  5. #
  6. # new file: foo/bar.txt
  7. #
  8. # Changed but not updated:
  9. # (use "git add <file>..." to update what will be committed)
  10. # (use "git checkout -- <file>..." to discard changes in working directory)
  11. #
  12. # modified: foo/bar.txt
  13. #

The same file in both sections, new and modified? 两个部分中的相同文件,新增修改? What should I do? 我该怎么办?


#1楼

参考:https://stackoom.com/question/CfwP/Git-无法撤消本地更改-错误-路径-已取消合并


#2楼

  1. git checkout origin/[branch] .
  2. git status

// Note dot (.) at the end. //注意末尾的点(。)。 And all will be good 一切都会好的


#3楼

This worked perfectly for me: 这对我很有用:

  1. $ git reset -- foo/bar.txt
  2. $ 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: 试试这个:

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

#6楼

我发现git stash对于所有'脏'状态的时间处理非常有用。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/564184
推荐阅读
相关标签
  

闽ICP备14008679号