恢复git中的一系列提交

编程入门 行业动态 更新时间:2024-10-27 23:22:49
本文介绍了恢复git中的一系列提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我怎样才能在git中恢复一系列的提交?从查看 gitrevisions 文档,我看不到指定我需要的范围。例如:

A - > B - > C - > D - > E - > HEAD

我想要做相当于:

git回复BD

结果如下:

A - > B - > C - > D - > E - > F - > HEAD

其中F包含与BD相反的值。

解决方案

您使用的是什么版本的Git?

仅在Git1.7.2 +中支持多个提交使用还原多次回滚到旧提交。了解更多详情。 当前 git revert 手册页仅适用于当前 Git版本(1.7.4 +)。

正如 OP Alex Spurling 评论中的报道:

升级到1.7.4可以正常工作。 要回答我自己的问题,这是我正在寻找的语法:

git revert B ^ .. D

B ^ 表示B的第一个父提交:允许在回复中包含 B 。 请参阅 git rev-parse 指定修订部分,其中包括 < rev> ^ ,例如 HEAD ^ 语法:请参阅插入符号( ^ )字符是什么意思?)

请注意,每个已还原的提交都是单独提交的。 p>

Henrik N 在评论:

如下所示,您可以立即恢复而无需立即提交:   

git revert -n OLDER_COMMIT ^ .. NEWER_COMMIT git commit -m将OLDER_COMMIT恢复为NEWER_COMMIT

How can I revert a range of commits in git? From looking at the gitrevisions documentation, I cannot see how to specify the range I need. For example:

A -> B -> C -> D -> E -> HEAD

I want to do the equivalent of:

git revert B-D

where the result would be:

A -> B -> C -> D -> E -> F -> HEAD

where F contains the reverse of B-D inclusive.

解决方案

What version of Git are you using?

Reverting multiple commits in only supported in Git1.7.2+: see "Rollback to an old commit using revert multiple times." for more details. The current git revert man page is only for the current Git version (1.7.4+).

As the OP Alex Spurling reports in the comments:

Upgrading to 1.7.4 works fine. To answer my own question, this is the syntax I was looking for:

git revert B^..D

B^ means "the first parent commit of B": that allows to include B in the revert. See "git rev-parse SPECIFYING REVISIONS section" which include the <rev>^, e.g. HEAD^ syntax: see more at "What does the caret (^) character mean?")

Note that each reverted commit is committed separately.

Henrik N clarifies in the comments:

git revert OLDER_COMMIT^..NEWER_COMMIT

As shown below, you can revert without committing right away:

git revert -n OLDER_COMMIT^..NEWER_COMMIT git commit -m "revert OLDER_COMMIT to NEWER_COMMIT"

更多推荐

恢复git中的一系列提交

本文发布于:2023-10-07 17:15:20,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:系列   git

发布评论

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

>www.elefans.com

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