使用git恢复提交的一部分 [英] Reverting part of a commit with git

查看:115
本文介绍了使用git恢复提交的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在git中恢复一个特定的提交。不幸的是,我们的组织仍然使用CVS作为标准,所以当我重新提交CVS时,多个git提交将合并为一个。

I want to revert a particular commit in git. Unfortunately, our organization still uses CVS as a standard, so when I commit back to CVS multiple git commits are rolled into one. In this case I would love to single out the original git commit, but that is impossible.

有没有类似于 git add的方法?在这种情况下,我很想挑出原始的git commit,但这是不可能的。 patch ,这将允许我选择性地编辑差异来决定要提交哪个部分进行还原?

Is there an approach similar to git add --patch that would allow me to selectively edit diffs to decide which parts of a commit to revert?

推荐答案

使用 - no-commit -n )选项< git revert ,然后取消更改,然后使用 git add --patch

Use the --no-commit (-n) option to git revert, then unstage the changes, then use git add --patch:

$ git revert -n $bad_commit    # Revert the commit, but don't commit the changes
$ git reset HEAD .             # Unstage the changes
$ git add --patch .            # Add whatever changes you want
$ git commit                   # Commit those changes

注意:你添加使用git add --patch是你想要恢复的文件,而不是你想保留的文件。

Note: The files you add using git add --patch are the files you want to revert, not the files you want to keep.

这篇关于使用git恢复提交的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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