Git:无法撤消本地更改(错误:path…未合并)
我有以下工作树状态
$ 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
在那里,我想再次得到它“不变状态”(类似于'svn回复'):
$ 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
这对我来说非常合适:
$ git reset -- foo/bar.txt $ git checkout foo/bar.txt
git checkout origin/[branch] . git status
//注意点(。)在最后。 一切都会好的
git checkout foo/bar.txt
你试过了吗? (没有HEAD关键字)
我通常以这种方式恢复我的更改。
我发现git隐藏非常有用的时间处理所有“脏”的状态。