gpt4 book ai didi

Git - 如何在分支之间移动提交

转载 作者:行者123 更新时间:2023-12-05 06:23:24 25 4
gpt4 key购买 nike

我有以下内容:

branch0  ---  commit1 --- commit2 --- branch2 --- commit3
|
branch1
|
commit4
|
commit5

我想将其更改为以下内容(即从 commit1 移动所有内容):

branch0
|
branch1
|
commit4
|
commit5 --- commit1 --- commit2 --- branch2 --- commit3

我尝试过使用rebasecherry-pick,但我的知识还不够,所以欢迎任何建议。

谢谢

更新

根据下面 mimikrija 的回答,我尝试了以下操作:

git checkout branch0
git checkout -b temp
git rebase branch1
## fix conflicts
git add .
git commit -am "rebase applied"
git rebase --continue
git branch -mv -f branch1

我收到以下错误:

fatal: Invalid branch name: 'HEAD'

git status
rebase in progress; onto 89844e6
You are currently rebasing branch 'temp' on '89844e6'.
(all conflicts fixed: run "git rebase --continue")

最佳答案

假设这些都是本地分支(尚未发布,或已发布但未被其他任何人使用),这些将是要采取的步骤。

git checkout branch2

git checkout -b temp 根据branch2创建一个临时分支

git rebase branch1 现在你有了你在图表中画的东西,但它叫做 temp

git branch -mv -f branch1 强制重命名分支

最后,从 branch2 中删除提交:

git checkout branch2

git reset --hard branch0

关于Git - 如何在分支之间移动提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58408550/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com