如何挑选合并提交+已合并的提交?

问题描述 投票:0回答:2

如果我有一个看起来像这样的分支:

M --- Merge Branch 'foobar' (sha ABC)
    o did stuff (sha DEF)
    o did other stuff (sha GHI)

我挑选合并提交:

git cherry-pick -m1 ABC

然后我将 ABC、DEF、GHI 全部集中在一次提交中...我希望实际上只具有与另一个分支相同的结构,并将合并+单独的提交分开。我该怎么做?

git
2个回答
0
投票

以下是实现类似目标的几种方法:

  • 使用
    rebase
# start with a temp branch at commit DEF :
git checkout -b temp DEF

git rebase targetbranch
# or, if the fork point between 'foobar' and 'targetbranch' is not
# at GHI, instruct rebase to only take commits starting from GHI :
git rebase --onto targetbranch GHI^

git checkout targetbranch
git merge --no-ff temp
git branch -d temp
  • 使用
    cherry-pick
# create a temp branch from your current tip :
git checkout -b temp

# list all commits to pick:
git cherry-pick GHI DEF

# merge temp branch into targetbranch:
git checkout targetbranch
git merge --no-ff temp
git branch -d temp
  • 使用
    cherry-pick
    (采取2):
# create a temp branch from your current tip :
git checkout -b temp

# the range of commits to pick should be :
# the range "first parent of M" .. "second parent of M"
git cherry-pick M^..M^2

# merge temp branch into targetbranch:
git checkout targetbranch
git merge --no-ff temp
git branch -d temp

0
投票
git checkout -b temp
git reset --hard ABC
git rebase -i --rebase-merges <original branch sha>

选择您想要挑选的合并提交并删除其他所有内容。这样做将包括合并中的提交,但代价是为合并提交创建新的 SHA。

© www.soinside.com 2019 - 2024. All rights reserved.