我建议您使用rebase onto
. 假设我们有以下回购:
user@HOST c:/_TEMP/FOO (AIOEC-393) $ git lga
* 8c2d5c5 - (HEAD, AIOEC-393) commit5 (Yanflea 2 minutes ago)
* 3c20e52 - commit4 (Yanflea 2 minutes ago)
* c5383af - commit3 (Yanflea 2 minutes ago)
* fb11e98 - commit2 (Yanflea 2 minutes ago)
* e019261 - (develop) commit1 (Yanflea 2 minutes ago)
* 0cfe064 - (master) Initial commit (Yanflea 2 minutes ago)
并且您希望获得AIOEC-393
除commit2之外的分支的所有提交。
让我们移动到一个“临时”分支(这样AIOEC-393
就不会被修改):
$ git checkout -b develop-target
然后使用commit2作为pivot的rebase onto
命令:
$ git rebase --onto develop fb11e98 develop-target
让我们看看日志:
user@HOST c:/_TEMP/FOO (develop-target) $ git lga
* 7bcb162 - (HEAD, develop-target) commit5 (Yanflea 2 minutes ago)
* 3c89459 - commit4 (Yanflea 2 minutes ago)
* e6ed5f7 - commit3 (Yanflea 2 minutes ago)
* e019261 - (develop) commit1 (Yanflea 2 minutes ago)
* 0cfe064 - (master) Initial commit (Yanflea 2 minutes ago)
现在我们只需要快进 from develop
to develop-target
(然后 remove develop-target
):
$ git checkout develop
$ git rebase develop-target
$ git branch -d develop-target
日志:
user@HOST c:/_TEMP/FOO (develop) $ git lga
* 7bcb162 - (HEAD, develop) commit5 (Yanflea 2 minutes ago)
* 3c89459 - commit4 (Yanflea 2 minutes ago)
* e6ed5f7 - commit3 (Yanflea 2 minutes ago)
* e019261 - commit1 (Yanflea 2 minutes ago)
* 0cfe064 - (master) Initial commit (Yanflea 2 minutes ago)