如何将多个提交还原为单个提交的一部分(How to revert multiple commits as part of a single commit)

编程入门 行业动态 更新时间:2024-10-27 01:33:52
如何将多个提交还原为单个提交的一部分(How to revert multiple commits as part of a single commit)

这不是一个主要问题,只是我想知道是否可能。

假设我们有两个提交abcd123和wxyz789 ,这些提交发生在非相邻的单独的地方,远远落后于回购历史。 现在我们想要恢复它们。 干

git revert abcd123 wxyz789

将导致两个单独的提交,一个返回abcd123 ,另一个返回wxyz789 。

这一切都很好,但是如果我们想在两个提交中修正的错误是逻辑关联的,为了自我文档的目的,我们想做一个单一的提交,包含一个单“ 我现在断了我正在还原文件x,y和z “评论? 有没有一个git命令呢?

(我当然知道可以创建一个提交,我只需手动修改所有的变化,然后再推,这对所有的这些讨厌的原因是很痛苦的。)

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.)

最满意答案

你可以做:

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

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

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.

更多推荐

本文发布于:2023-07-09 00:16:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1082140.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   如何将   原为   revert   multiple

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!