需要将分支上的旧推送提交拆分为多个

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

分支上有30个推送的提交。有必要将分支上的第二个提交拆分为20个以上的提交,而不会损坏以下提交(在第一个和下一个28个提交之间插入拆分的提交)。分支上的第二次提交具有大量更改,可以将其放置在20多个提交中。

是否有可能在不损害后续提交的情况下进行拆分?

git git-commit git-rebase git-remote git-reset
2个回答
0
投票

确定...这需要您做一些工作。简短的答案是yes,有可能。长答案:这需要一些工作。

git branch second second-commit-id
# we have placed a commit on the original second revision
git checkout -b temp second-commit~
# we checkout a new branch called temp placed on the parent of second... this is where the trick starts

每次迭代都需要您执行以下步骤(会有20个,对吧?]

git checkout --detach second # we place ourselves on the target _content_ revision... detached HEAD
git reset --soft temp # set branch pointer on the previous iteration revision
# now you start checking the files and leave the content you want it to be for _this_ iteration...
# compare contents with both previous iteration (temp) and target revision (second)
# add the files when you are ready
git commit -m "A new iteration... write the proper message"
# now we need to set temp where we are
git branch -f temp # temp is now where we are

您将在多次迭代中重复该过程,直到达到温度像秒一样的时间

然后您可以继续:

# replicate all changes from second up to the tip of the real branch
git cherry-pick second..master # or whatever branch you are rewriting
# if you like the result
git branch -f master # place master or whatever branch over here
git checkout master

现在您已经完成了工作。


0
投票

分支上有30个推送的提交。有必要将分支上的第二个提交拆分为20个以上的提交,而不会损坏以下提交]

git checkout -b newbranch thatcommit
git reset @^

现在您在新分支上,您的工作树包含thatcommit快照,并且索引和父级设置为其父级。依次添加并提交更改,每次替换提交:

git add --patch   # or --interactive
git commit

或者,如果您幸运的话,更改是独立的,包含在单独的文件中,您可以只提交单个文件(有关指定提交路径或提交路径时会发生的事情,请参见文档。

现在您已经有了thatcommit的替换系列。在本地将每个具有thatcommit父级的提交设置为将替换提示作为父级:

thatcommit=`git rev-parse thatcommit`
newbranch=`git rev-parse newbranch`
git rev-list --ancestry-path --all --parents ^thatcommit \
| sed -n s/$thatcommit/$newbranch/p > .git/info/grafts

并使用git filter-branch烘焙重新连接的祖先:

git filter-branch -- --all

如果您不喜欢结果,请退出:

git fetch . +refs/original/*:*

并进行清理(任一种方式:)>]

git filter-branch -f --setup exit
rm -f .git/info/grafts
    
© www.soinside.com 2019 - 2024. All rights reserved.