英文:
should I git rebase twice?
问题
-
如何重新基于两个分支并保持结构?(过去当我重新基于分支的尖端时,那个分支被重新基于,但其他分支保持不变)
-
是否有一种方法可以在主分支上重新创建“MyAwesomeFeature”分支,然后在主分支上创建仅包含“MyExperiment”的更改的另一个分支?
英文:
I have the following situation with a repo.
Over the master branch I made a branch "MyAwesomeFeature" and made several commits.
Later the remote master moved so I git pull origin master
and later rebased my branch to the top of master. No problem there
I wanted to try an experiment in my branch, so I did git checkout -b MyExperiment
over MyAwesomeFeature branch.
Now master has moved again.
So my question is
-
How can I rebase both branches and keep the structure? (in the past when I rebased the tip, that was the branch rebased but the other stayed )
-
Is there a way that I can rebranch "MyAwesomeFeature" over master and then create another branch over master with only the changes of MyExperiment?
答案1
得分: 1
自Git 2.38.0版本开始,您只需将“最长”的分支进行变基并使用 --update-refs
:
git switch MyExperiment
git rebase -i --update-refs origin/master
这将为您更新MyAwesomeFeature
。
在Git 2.38之前,您可以选择不同的方法。进行两次变基:
git rebase origin/master MyAwesomeFeature
git rebase --onto MyAwesomeFeature MyAwesomeFeature@{1} MyExperiment
或者只进行一次变基,但需要手动重新设置更新后的分支:
git rebase origin/master MyExperiment
git log origin/master.. # 查找MyAwesomeFeature应指向的新提交
git branch -f MyAwesomeFeature <that_commit>
英文:
Starting with Git 2.38.0, you would rebase only the "longest" branch and use --update-refs
:
git switch MyExperiment
git rebase -i --update-refs origin/master
This will update MyAwesomeFeature
for you.
Before Git 2.38 you can choose different approaches. Rebase twice:
git rebase origin/master MyAwesomeFeature
git rebase --onto MyAwesomeFeature MyAwesomeFeature@{1} MyExperiment
Rebase once, but reseat the updated branch manually:
git rebase origin/master MyExperiment
git log origin/master.. # look up the new commit that MyAwesomeFeature should point to
git branch -f MyAwesomeFeature <that_commit>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论