如何将多次提交恢复为单次提交的一部分 [英] How to revert multiple commits as part of a single commit

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

问题描述



假设我们有两个提交, abcd123 wxyz789 ,这些发生在非相邻的独立位置,远在回购商的历史记录中。现在让我们说我们想要恢复它们。做的

  git revert abcd123 wxyz789 

会导致两个单独的提交,一个恢复 abcd123 ,另一个恢复 wxyz789



这很好,但如果我们想要在两个提交中修复的错误是逻辑链接的,并且出于自我记录的目的,我们会喜欢做一个单独的提交包含一个单独的我打破了一些东西,所以现在我正在恢复文件x,y和z 评论?有没有这样做的git命令?



(我当然知道可以创建一个提交,我只需手动修复所有更改然后推送。 )

解决方案

您可以这样做:

  git revert abcd123 
git revert --no-commit wxyz789
git commit --amend

...然后编写一条适当的提交消息,描述恢复提交的组合效果。


This is not a major problem, just something I want to know whether or not is possible.

Let's say we have two commits, abcd123 and wxyz789, that occur at non-adjacent, separate places, far back in a repo's history. Now let's say we want to revert them. Doing

git revert abcd123 wxyz789

would result in two separate commits, one reverting abcd123 and the other reverting wxyz789.

This is all fine and well, but what if the mistakes we want to fix in the two commits are logically linked, and for the purposes of self-documentation we'd like to make one single commit containing one single "I broke something so now I'm reverting files x, y and z" comment? Is there a git command that does this?

(I am of course aware that it is possible to create a commit where I just manually fix all the changes and then push. This is painful for all the obbious reasons.)

解决方案

You can do:

git revert abcd123
git revert --no-commit wxyz789
git commit --amend

... and then write an appropriate commit message describing the combined effect of reverting both commits.

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

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