使 git 功能分支保持最新的更简单方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9587686/
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
Easier way to keep a git feature branch up to date
提问by hafichuk
I was wondering if anyone would have a better suggestion for keeping a feature branch in sync with it's parent branch.
我想知道是否有人会有更好的建议来保持功能分支与其父分支同步。
We typically have multiple feature branches that are being worked on at a time, each derived from our develop
branch. It's fairly common for feature branches to be merged into develop
a couple times a day.
我们通常一次处理多个功能分支,每个develop
分支都来自我们的分支。功能分支develop
每天合并几次是很常见的。
In order to stay on top of changes (i.e. resolve conflicts) I find I need to keep the feature branches I'm actively working on up to date with develop
.
为了随时掌握变化(即解决冲突),我发现我需要保持我正在积极开发的功能分支与develop
.
To do this I run these commands a couple times a day:
为此,我每天运行这些命令几次:
git checkout develop
git pull
git checkout feature/foo
git merge develop
git push
The last git push
I usually only do if I'm working with someone else on the feature branch.
最后git push
我通常只在我与功能分支上的其他人一起工作时才这样做。
Is there a better or more convenient way to do this?
有没有更好或更方便的方法来做到这一点?
回答by Wes Hardaker
Well, git is really set up for wrapping things you do frequently into a script and then calling the script instead. There isn't a huge number of variations on the above. They all will require pulling the upstream branch, and then integrating your changes with the upstream's. Some things that may shorten it for you might be:
好吧,git 确实是为将您经常做的事情包装到脚本中然后调用脚本而设置的。上面没有大量的变化。它们都需要拉动上游分支,然后将您的更改与上游的集成。一些可能为您缩短它的事情可能是:
git checkout feature/foo
git pull --all
git rebase develop
That way you can simply pull all the upstream branches in one shot without switching to the other branch. And rebasing is possibly an operation you may prefer over merging, but that's frequently a personal choice depending on how you want the history to look.
这样你就可以简单地一次拉动所有上游分支,而无需切换到另一个分支。变基可能是您可能更喜欢合并而不是合并的操作,但这通常是个人选择,具体取决于您希望历史记录的外观。
回答by Barney
Why not make a script that would run the commands?
为什么不制作一个可以运行命令的脚本呢?
Create merge-develop.sh
with text
merge-develop.sh
用文字创作
#!/bin/bash
git checkout develop
git pull
git checkout feature/
git merge develop
git push
Then simply run merge-develop.sh foo
.
然后简单地运行merge-develop.sh foo
。