Git:如何使用 dev 中所做的更改来更新本地功能分支?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18518923/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git: How to keep local feature branch updated with changes made in dev?
提问by Jeff
I've been following this guide for working with distributed git projects: http://nvie.com/posts/a-successful-git-branching-model/. It has worked well but now I have run into a snag. I have created a local feature branch. I would like to keep this feature branch up-to-date with the latest changes made in dev
. Is this possible? I was researching this and found I would probably need to use rebase
. But there were so many options I didn't know exactly which one I needed to use. How would I do this?
我一直在遵循本指南来处理分布式 git 项目:http: //nvie.com/posts/a-successful-git-branching-model/。它运作良好,但现在我遇到了障碍。我创建了一个本地功能分支。我想让这个功能分支与dev
. 这可能吗?我正在研究这个,发现我可能需要使用rebase
. 但是有太多的选择,我不知道我需要使用哪一个。我该怎么做?
回答by Matt Ball
Periodically:
定期:
λ git checkout dev
λ git pull origin dev
λ git checkout myfeaturebranch
λ git merge dev
回答by Derek S
Running git rebase dev
while on the feature branch should do the trick (update local dev from origin first, if necessary).
git rebase dev
在功能分支上运行应该可以解决问题(如有必要,请首先从原点更新本地开发)。
That will replay your changes from the feature branch onto dev, then sets the feature head to be the head of the new history.
这会将您从功能分支的更改重播到 dev,然后将功能头设置为新历史的头。
Note: Only rebase
if your feature branch commits have not yet been pushed. It will rewrite your history.There are some caveatswith rebase
which may or may not be worth the risk.
注意:仅rebase
当您的功能分支提交尚未推送时。它会改写你的历史。还有一些注意事项有rebase
可能会或可能不值得冒险。