恢复 git 中的一系列提交 [英] Revert a range of commits in git
问题描述
如何恢复 git 中的一系列提交?通过查看 gitrevisions 文档,我看不到如何指定我需要的范围.例如:
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
我想做相当于:
git revert B-D
结果会在哪里:
A -> B -> C -> D -> E -> F -> HEAD
其中 F 包含 B-D 的倒数.
where F contains the reverse of B-D inclusive.
推荐答案
你用的是什么版本的Git?
What version of Git are you using?
仅在 Git1.7.2+ 中支持恢复多个提交:请参阅使用 revert 多次回滚到旧提交." 了解更多详细信息.
当前的 git revert
手册页 仅适用于 当前 Git 版本 (1.7.4+).
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+).
正如 OP Alex Spurling 在评论中报告的那样:
As the OP Alex Spurling reports in the comments:
升级到 1.7.4 可以正常工作.
为了回答我自己的问题,这是我正在寻找的语法:
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^
表示B 的第一个父提交":允许在还原中包含 B
.
请参阅git rev-parse
指定修订部分" 其中包括 <rev>^
,例如HEAD^
语法:在什么是插入符号 (^
) 字符是什么意思?")
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.
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 中的一系列提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!