有没有更快的方法来集成功能分支?
我经常发现自己做的事情是“重新建立一个功能分支,合并它并删除它。”为此,我运行:
git rebase master feature
git checkout master
git merge feature
git branch -d feature
对于我想象的常见工作流程来说,这似乎相当费力。有谁知道更快的方法吗?
(显然我可以编写一个脚本,但我想知道是否有我错过的内置方法。)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
一般方法仍然是编写脚本或定义别名,如“带有位置参数的 git 别名< /a>”:
The general approach remains scripting or defining aliases, as illustrated in "Streamline your git workflow with aliases", except you might need a parameter as in "git alias with positional parameters":
如果您已经在 master 上,那么将其合并并删除它会更快(
git merge feature
和gitbranch -d feature
)。这只是两个命令,您可以避免仅仅为了快进而重新检查旧的母版。
您还只需执行一次解析,而不是潜在的多个解析,因为您可能需要对功能分支的多个提交进行变基。
此外,您的历史记录可以更好地反映功能分支实际开发的提交。
rebase
破坏了这段历史。If you're on master already then it would be faster to just merge it in and delete it (
git merge feature
andgit branch -d feature
).That's just two commands and you avoid re-checking out an old master simply to fast-forward it.
You'll also just do a single resolve instead of potentially multiple resolves as you might require rebasing multiple commits of the feature branch.
In addition, your history better reflects what commit the feature branch was actually developed on top of.
rebase
destroys this history.看来您的合并分支与 rebase 分支完全相同,因此您只需将其重命名为 master (其中
-M
标志强制其作为 master 已经存在)It seems that your merged branch is exactly the same the as rebase one, therefore you can just rename it to master (wich the
-M
flag to force it as master already exists)您可以保存一个命令(在变基后,合并无论如何都会解析为快进):
但最好按照其他人的建议使用别名,或者根本不变基,只需合并
You can save one command (after rebase the merge will resolve to a fast-forward anyway):
But better use aliases as others have suggested or don't rebase at all, simply merge