问题描述
master是我们的stable分支
$ git status
#分支大师
没有提交(工作目录干净)
在分支上创建模块
$ git checkout -b foo
$ echohello>世界
$ git add。
$ git commit -minit为foo模块提交
$ git checkout master
$ git merge foo
$ git checkout -b foo
$ echohello>世界
$ git add。
$ git commit -minit为foo模块提交
$ git checkout master
$ git merge foo
在主分支或其他分支上工作
在接下来的几周内,更多的代码将被委托直接和其他分支分支机构。 foo
分支在这段时间内将保持不变
恢复工作/在foo分支上进行更新
$ git checkout foo
foo 已经过时了!我理解为什么,但是 do 需要 foo
重新同步。
问题
如何从 master
分支获取最新内容?
如果您不需要这个分支:
如果您已将foo合并回主,那么git branch -d foo将杀死主题分支,然后在将来需要再次破解时使用checkout -b foo。
如果您确实需要分支:
master分支:
git checkout foo
git rebase master
或者:
git rebase master foo
Here's a common workflow hurdle I encounter often:
master is our "stable" branch
$ git status
# On branch master
nothing to commit (working directory clean)
create a module on a branch
$ git checkout -b foo
$ echo "hello" > world
$ git add .
$ git commit -m "init commit for foo module"
$ git checkout master
$ git merge foo
do work on master or other branches
Over the next couple weeks, more code will be committed to master directly and by other branches. foo
branch will go untouched for this time period
resume work/make updates on foo branch
$ git checkout foo
Oh no! foo
is massively out of date! I understand why, but I do need foo
back in sync.
the question
How do I get the latest contents from the master
branch?
If you don't need the branch around:
If you've merged foo back to master, "git branch -d foo" to kill the topic branch, and then "checkout -b foo" in the future when you need to hack on it again.
If you do need the branch around:
You can rebase your topic branch against the master branch:
git checkout foo
git rebase master
Or:
git rebase master foo
这篇关于如何在同一个Git仓库中同步两个分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!