小编典典

Git:无法撤消本地更改(错误:路径...未合并)

all

我有以下工作树状态

$ 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 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

现在它变得越来越混乱:

$ 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
#

两个部分中的相同文件,新的 修改的?我该怎么办?


阅读 223

收藏
2022-03-22

共1个答案

小编典典

你做错了。您应该首先重置,取消暂存文件,然后签出,以恢复本地更改。

尝试这个:

$ git reset foo/bar.txt
$ git checkout foo/bar.txt
2022-03-22