2

我有类似的提交

Initial->FeatureX->B->C->D->FixBugInFeatureX->E->F->

现在我想用 FeatureX,FixBugInFeatureX 进行一次提交

所以我尝试了

   git -rebase -i -<FeatureX>

然后,我将提交 FixBugInFeatureX 移动到文本文件中 FeatureX 之后,并将其从更改picksquash This works if there is no conflict. 但它向我展示了一个新分支,其中包含所有重写的提交 Initial->FeatureX->B->C->D->FixBugInFeatureX->E->F。我可以将此分支合并到我的 Head 中 - 但我仍然有所有以前的提交(FixBugInFeatureX 现在第二次包含 FeatureA。更重要的是,提交 B、C 和 D 之间的所有提交现在都存在两次。

我想要的是一个新的提交树

Initial->FeatureX->B->C->D->E->F

我怎样才能像这样变基 - 还是我需要不同的命令?

4

2 回答 2

0

您可以检查您的 FeatureX 和 FixBugInFeatureX 提交(然后您将处于分离的头部状态)并将它们提交到 2 个新分支

git checkout <FeatureX> 
git checkout -b featureX

git checkout <FixBugInFeatureX>
git checkout -b bugfix

然后将这些分支合并在一起,这样原始提交和修复之间就不会有任何冲突

git merge featureX

然后你可以检查你的主人(或包含该链的分支)了

git checkout master

并运行 git rebase 交互模式来重新设置您的主分支和包含您的 FeatureX 的固定版本的分支。

git rebase -i bugfix

只需为提交提供您想要的顺序,rebase 将为您完成其余的工作(您希望链的顺序)

于 2012-08-15T15:22:24.677 回答
0

我找到了解决方案:

rebase --interactive 完成这项工作,如果我在初始提交之前将提交的哈希传递给 squash:

git rebase  -i --no-autosquash "<hash of comitt BEFORE FeatureX>"

这将打开一个文本文件,如

pick 07b952c some unrelated committ 
pick 6c46e25 FeatureX
pick b4bc625 B
pick f2fab98 C
pick dc6ba8b D
pick 5633408 FixBugInFeatureX
pick 077888f E
pick 0123445 F

# Rebase xxx..yyy onto zzz
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

我现在可以将此文件修改为

pick 07b952c some unrelated committ 
pick 6c46e25 FeatureX
squash 5633408 FixBugInFeatureX
pick b4bc625 B
pick f2fab98 C
pick dc6ba8b D
pick 077888f E
pick 0123445 F

并且 git 会将两个提交压缩在一起。之后将显示一个可编辑的文本文件,我可以在其中编辑 6c46e25 的新提交消息,现在还包括 5633408

如果在两个提交之间进行了合并或推送/拉取,这将无法令人满意。这导致至少在我的试验中重复历史。但除此之外,这正是我想要的。没有重复的历史。显然,重点是在第一次提交编辑之前传递提交的哈希值。

于 2013-03-27T11:13:22.663 回答