git:如何将某个作者的所有提交变基到一个单独的分支中?

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

我正在使用一些没有使用 SCM 的代码+ 并偶尔收到所有项目文件形式的更新,尽管其中只有一些只做了一点更改。到目前为止,我只是将自己的更改放在 git 存储库中,并通过手动

git add -p
会话解决了这些“更新”,这对我自己的更改量(那些尚未确定要发布的更改)越来越烦人) 增加,因为幸运的是我为上述“补丁”做了
git commit --author "the others"
,我想知道:

一个作者所做的所有提交如何分离到一个新的分支中?

(我不介意在这种情况下重写历史,repo 仅供我使用)

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


+ 是的,绝地武士确实感觉你在那儿畏缩

git version-control branch git-rebase
2个回答
7
投票

我最近为某人做了这个:

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

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

附注。而不是

git add -p
,我会使用
git gui
。一开始我对使用 gui 持怀疑态度,但现在没有
git gui
gitk
(或 Mac 上的
gitx
)我就活不下去了。

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