git:如何将某个特定作者的所有提交重新绑定到一个单独的分支中?

时间:2011-04-14 12:34:12

标签: git version-control branch git-rebase

我正在使用一些代码,其中没有使用SCM + ,并且会以所有项目文件的形式偶尔接收更新,尽管其中只有一些更改了一些。到目前为止,我只是将自己的更改放在一个git repo中并用手动git add -p会话解决了这些“更新”,这对我自己的更改(那些未确定为已经发布了)并且幸运地我为前面提到的“补丁”做了git commit --author "the others",我想知道:

  

如何将一位作者提交的所有提交分成新的分支?

(我不介意在这种情况下重写历史记录,回购只由我使用)

理想的解决方案包括在每个“补丁”之后将其他分支合并到我的分支中,但是现在最后的合并可能就足够了。


+ 是的,Jedi 确实感到你在那里畏缩

2 个答案:

答案 0 :(得分:6)

我最近为某人做了这个:

git checkout -b other_work <sha1_of_where_to_rebase>
git log --reverse --author=others --format=%H <sha1_range> | xargs -n 1 git cherry-pick

希望这有帮助

答案 1 :(得分:2)

我不太了解你在做什么,但你用第三方代码库描述的问题被称为“供应商分支”。以下是我将如何处理它:

为第三方版本制作分支,例如vendor。我假设您的分支被称为master。当他们发布新版本时,您可以执行以下操作:

git stash # If you have any uncommitted files
git checkout vendor
tar -xzvf [new files]  # This might be unzip or whatever, rather than tar
git commit -am "Version xxx from upstream"  # Adjust commit message to suit
git checkout master
git merge vendor   # Bring changes into your branch (you could use rebase here if you prefer to keep all your changes on top of all their changes)
git stash pop # Restore your uncommitted files

PS。而不是git add -p,我会使用git gui。我对使用gui开始持怀疑态度,但我现在不能没有git guigitk(或者gitx在Mac上)。