Git-更改“原始提交”分支的 [英] Git - Change "origin commit" of a branch
问题描述
我很难找到一个Git通用工作流来从分支中删除一些提交(在2个引用之间);这是一个小例子:
I have some difficult to found a Git generic worflow to remove some commits (between 2 refs) from a branch ; here is a little example :
我当前的状态是这样的:
My current state are like this :
* a878646 (develop) C8a
* 070acb7 C7a
| * 7937ce7 (HEAD, F1) C9b
| * fb4add2 C8b
| * 30456de C7b
|/
* 6a0999e C6
* 45ae978 C5
* e8a2eeb (tag: T3, master) C4
* 24b98b2 (tag: T2) C3
* c874fc7 (tag: T1) C2
* a853900 C1
在平台上测试 F1,但仅在主平台上测试 F1。
I want to test "F1" on my plateform, but ONLY the commits of "F1" on master.
换句话说,我希望F1变成这样:
In other word, I would like that F1 becomes like this :
* 7937ce7 (HEAD, F1) C9b
* fb4add2 C8b
* 30456de C7b
* e8a2eeb (tag: T3, master) C4
* 24b98b2 (tag: T2) C3
* c874fc7 (tag: T1) C2
* a853900 C1
所以我必须删除提交C5和C6。
So I have to remove commits C5 and C6.
在测试之后,应该合并F1
After the tests, F1 should be merge on master.
但是,这些提交必须保留在 develop分支上,因为在那之后,我必须进行 git checkout development&& git rebase origin / master
But, these commits have to stay on "develop" branch, because after that I have to do a "git checkout develop && git rebase origin/master"
开发结果应为:
* a878646 (HEAD, develop) C8a
* 070acb7 C7a
* 6a0999e C6
* 45ae978 C5
* 7937ce7 C9b (tag: T4, master)
* fb4add2 C8b
* 30456de C7b
* e8a2eeb (tag: T3) C4
* 24b98b2 (tag: T2) C3
* c874fc7 (tag: T1) C2
* a853900 C1
有没有一种方法可以简单地做到这一点?
这个问题是经常发生的,我搜索另一种方法,而不是用一次提交多次提交的樱桃采摘来完成它。
Is there a way to accomplish that simply ? This problem is recurrent, and I search another way than doing it with multiple "cherry-pick" one comits by one commits...
我搜索一个方式仅使用 master, F1,并且不知道这些分支之间以及在F1中的提交次数:/
I search a way just using "master", "F1", and without knowing number of commits bewteen these branches and in F1 :/
我认为我可以使用改成,但我不太了解...
非常感谢!
推荐答案
使用 rebase --onto
Using rebase --onto
git checkout F1
git rebase 6a0999e --onto master
或
git checkout F1
git rebase develop --onto master
使用 git rebase -i
Using git rebase -i
git checkout F1
git rebase -i master
# Remove lines with C5 and C6 and save.
使用 git cherry-pick
Using git cherry-pick
git checkout master
git cherry-pick 6a0999e..7937ce7 # note that 6a0999e commit will not be cherry-picked - this is the commit before split
git branch F1 HEAD -f # move F1 ref to current commit
请注意,提交散列将与您的开发结果列表(在每个版本中)不同。
Note that commit hashes will be different than on your "result on develop" list (in every version).
这篇关于Git-更改“原始提交”分支的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!