使用"git revert"取消添加行的更改? [英] Use "git revert" to back-out a change adding a line?

查看:422
本文介绍了使用"git revert"取消添加行的更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的pastebin是一个回购协议,其中一个文件,每行键入一个,两个,三个,四个,五个.

The following pastebin is a repo with one file with one, two, three, four, five typed on each line.

每行分别提交到git:

Each line was commited separately into git:

http://pastebin.ca/raw/2136179

然后我尝试使用命令git revert <commmit which creates two>

并获得:

error: could not revert b4e0a66... second
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'

这么简单的东西应该没有冲突吗?还是我做错了/错了命令?

There should be no conflict for something this simple? Or am I doing it wrong/got the wrong command?

合并细节似乎也没有道理

The merge details don't seem to make sense either:

one
<<<<<<< HEAD
two
three
four
five
=======
>>>>>>> parent of b4e0a66... second

这不是删除所有内容,而是删除所有内容吗?我原本只希望有两个人受到影响...

Isn't that saying delete everything but one? I was expecting only two to be affected...

git 1.7.10

git 1.7.10

推荐答案

我尝试重复您的步骤,发现了相同的问题.看来您只能还原最近的提交. 在我的存储库中:

I tried to repeat your steps and found the same problem. It seems that you can revert only the most recent commits. In my repository:

$ git log --oneline
9a25594 five
f8f1ec4 four
3c75345 three
e6cd245 two
8349ccc one
d2f16c4 for stkofl  <<==== ignore this one

$ git revert 9a25 --no-edit
Finished one revert.
[master 82bbc79] Revert "five"
 1 files changed, 0 insertions(+), 1 deletions(-)
$ git reset --hard
HEAD is now at 82bbc79 Revert "five"

似乎不允许还原任何不是包括HEAD(最近的提交)在内的连续提交的提交集.

Reverting any set of commits that is not a set of consecutive commits including HEAD (the most recent commit) seems to be disallowed.

当然,您可以这样做:

    $ git show e6cd |patch -R
    patching file file
    Hunk #1 succeeded at 1 with fuzz 1.

然后提交结果.

这篇关于使用"git revert"取消添加行的更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆