我有一个Sprint分支(Sprint1
)由多个功能分支组成(从最新到最旧列出):
我想在一次操作中删除来自Feature#2分支的Sprint分支中的所有内容。有没有办法可以做到这一点?
实际上,我在Feature#2上有超过3次提交,并且不想在我错过提交的情况下逐个还原它们。我将要解决许多合并冲突,因为功能#3和#4是基于功能#2构建的,现在需要独立。我只想提取功能#2并一次解决所有合并冲突。
根据RomainValeri的要求,以下是从我的git log --oneline --decorate --simplify-by-decoration --all
分支运行Sprint1
的结果:
f12b0af (HEAD -> Sprint1) Merge of Feature #3 and Feature #4.
70c028b (Feature3) Feature #3, Commit #2
216764a (Feature4) Feature #4, Commit #1
060d98e (Feature2) Feature #2, Commit #3
2069da0 (Feature1) Feature#1 Commit #1
1d05fc0 (master) First Commit
让我们假设这里的名字:sprint
为sprint分支,你试图从feature2
分支恢复所有。
# next line was my first idea but probably no good
git rev-list $(git merge-base sprint feature2)..feature2
# since we have master as a ref for the merge-base, let's go simpler
git rev-list master..feature2
# or, if feature2 is branched of feature1 :
git rev-list feature1..feature2
将为您提供要还原的提交列表。
(如果你已经删除了feature2
,只需在合并到sprint
之前的提交中重新创建它,或者从reflog中获取它)
然后你可以链接恢复而不提交并在最后提交一次:
git revert -n <commit1>
git revert -n <commit2>
...
git commit -m "Revert of commits 1, 2, 3, ..."
但是我不会进一步自动化这个过程,因为你可能不得不一路上解决冲突。