如何在同一个Git存储库中同步两个分支? [英] How do I synchronize two branches in the same Git repository?
问题描述
这是我经常遇到的常见工作流程障碍:
Here's a common workflow hurdle I encounter often:
$ git status
# On branch master
nothing to commit (working directory clean)
在分支上创建模块
$ git checkout -b foo
$ echo "hello" > world
$ git add .
$ git commit -m "init commit for foo module"
$ git checkout master
$ git merge foo
在master或其他分支机构上工作
在接下来的几周内,将有更多代码直接或由其他分支机构负责掌握.在这段时间内,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. The foo
branch will go untouched for this time period.
$ git checkout foo
哦,不! foo 已经过时了!我了解为什么 ,但是我确实需要 foo 同步.
Oh no! foo is massively out of date! I understand why, but I do need foo back in sync.
如何从 master 分支获取最新内容?
How do I get the latest contents from the master branch?
推荐答案
如果不需要分支:
如果您将foo合并回master,则可以使用"git branch -d foo"杀死主题分支,然后在将来需要再次对其进行黑客攻击时将其"checkout -b foo"合并.
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.
如果您需要以下分支机构:
您可以根据主分支来重新建立主题分支:
You can rebase your topic branch against the master branch:
git checkout foo
git rebase master
或者:
git rebase master foo
这篇关于如何在同一个Git存储库中同步两个分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!