Git - 如何在父级rebase之后修复子分支

时间:2014-07-11 11:53:25

标签: git branching-and-merging

目前我有3个分支:master,develop和feature / x

我确实在主人身上发展了。我花了几个小时才完成它,几百次提交......所有这些都是为了提交一段美好的历史:)

将feature / x(之前基于开发)的最快方法与开发相同的历史是什么? feature / x有一些更改,仍然保留旧的过于复杂的提交历史记录。没有必要保留在feature / x上进行的任何新提交,它们可以被压缩为一个。

我基本上需要的是

git checkout develop
git checkout -b feature/y

然后以某种方式应用

git diff develop..feature/x

在feature / y之上。不知道git是否支持类似的东西。之后,我可以使用feature / y覆盖feature / x。

有关如何应用差异的任何想法,还是有更好的方法来做到这一点?

2 个答案:

答案 0 :(得分:1)

如果您乐意将feature/x分支中的差异压缩到单个提交中,这将有效:

# create a new branch identical to 'develop'
git checkout -b tmp develop
# make the working tree identical to the 'feature/x' branch
git diff HEAD feature/x | git apply -
# add any new files that were added to the 'feature/x' branch
git add foo/bar baz.txt
# commit
git commit -a -m 'Rebase feature/x on develop'
# rename the feature branch
# (or just delete it, you can get it back from 'git reflog')
git branch -m feature/x feature/x.old
# rename the 'tmp' branch to 'feature/x'
git branch -m tmp feature/x

现在feature/x的历史记录与develop相同,并且提前一次提交。

答案 1 :(得分:1)

尝试使用git cherry-pick

假设你已经将你的功能分支中的任何内容压缩成一个提交,而一个功能/ y分支只是做了一个

git cherry-pick thecommithash

这应该可以解决问题。

你可以通过逐个挑选来保留多个提交。

相关问题