我有四个分支(master, b1, b2和b3)。我在b1-b3上工作后,我意识到我在分支主上有一些应该在所有其他分支中更改的东西。我改变了我在master中需要的东西…这是我的问题:

我如何用主分支代码更新所有其他分支?


当前回答

如果你一直在一个分支上断断续续地工作,或者在你工作的时候其他分支发生了很多事情,最好将你的分支重新建立在master上。这样可以保持历史的整洁,使事情更容易理解。

git checkout master
git pull
git checkout local_branch_name
git rebase master
git push --force # force required if you've already pushed

注:

不要改变你与他人合作的分支。 您应该基于将要合并到的分支,该分支可能并不总是主分支。

http://git-scm.com/book/ch3-6.html上有一章是关于改变基础的,网上还有很多其他的资源。

其他回答

有两种方法

您希望将主分支合并到您的分支中 - git checkout master - git拉 - git checkout your-feature-branch - git merge master //解决冲突并提交 - git push

2:如果你想在main的基础上重新调整你的改变。

 git checkout master #Switch to main branch
 git pull #Take latest
 git checkout your-feature-branch #Switch to story branch
 git pull --ff-only # Ensure branch is up to date
 git rebase -i origin master #Interactively rebase your commits on top of master. So your changes are on top of latest commits in main.
 git rebase --continue #Resolve conflicts and rebase --continue to continue with next commits
 git push -f origin your-feature-branch # As you have rewritten the commit history, you have to **force push** the commits

Git rebase master是正确的方法。合并意味着将为合并创建一个提交,而重基则不会。

用你的主分支副本更新其他分支,如(备份)。 你可以按照任何一种方式(rebase或merge)…

做rebase(不会有任何额外的提交到备份分支)。 合并分支(将有一个额外的自动提交到 备份分支)。 注:Rebase只是建立一个新的base(一个新的副本)

git 结帐备份 Git 合并大师 git push

(重复执行其他分支,如backup2等)

git 结帐备份 git 变基大师 git push

(重复执行其他分支,如backup2等)

如果你想要恢复到上一次提交并删除日志历史记录

使用下面的命令,让我们假设你想要去到以前的提交,它有commititid SHA - 71e2e57458bde883a37b332035f784c6653ec509,你可以指向这个提交,它将不会显示任何日志消息在这个提交之后,所有的历史将被擦除。

git push origin +71e2e57458bde883a37b332035f784c6653ec509^:master

你有两个选择:

第一个是合并,但是这为合并创建了一个额外的提交。

检查每个分支:

git checkout b1

然后合并:

git merge origin/master

然后推:

git push origin b1

或者,你可以做一个rebase:

git fetch
git rebase origin/master