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

本文翻译自: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对于所有'脏'状态的时间处理非常有用。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值