有没有更快的方法来集成功能分支?

发布于 2024-12-05 16:31:37 字数 243 浏览 1 评论 0 原文

我经常发现自己做的事情是“重新建立一个功能分支,合并它并删除它。”为此,我运行:

git rebase master feature
git checkout master
git merge feature
git branch -d feature

对于我想象的常见工作流程来说,这似乎相当费力。有谁知道更快的方法吗?

(显然我可以编写一个脚本,但我想知道是否有我错过的内置方法。)

Something I often find myself doing is, "Rebase a feature branch, merge it & delete it." To do that I run:

git rebase master feature
git checkout master
git merge feature
git branch -d feature

That seems quite laborious for something I'd imagine to be a common workflow. Does anyone know a faster way?

(Obviously I could write a script, but I'm wondering if there's a built-in approach I've missed.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

童话 2024-12-12 16:31:37

一般方法仍然是编写脚本或定义别名,如“带有位置参数的 git 别名< /a>”:

rebmrg = "!f() { git rebase master $1; git checkout master ; git merge $1 ; git branch -d $1 }; f"

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":

rebmrg = "!f() { git rebase master $1; git checkout master ; git merge $1 ; git branch -d $1 }; f"
暗地喜欢 2024-12-12 16:31:37

如果您已经在 master 上,那么将其合并并删除它会更快(git merge featuregitbranch -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 and git 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.

幽蝶幻影 2024-12-12 16:31:37

看来您的合并分支与 rebase 分支完全相同,因此您只需将其重命名为 master (其中 -M 标志强制其作为 master 已经存在)

git rebase master feature
git branch -M feature 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)

git rebase master feature
git branch -M feature master
谜兔 2024-12-12 16:31:37

您可以保存一个命令(在变基后,合并无论如何都会解析为快进):

git rebase master feature
git checkout -B master
git branch -d feature

但最好按照其他人的建议使用别名,或者根本不变基,只需合并

You can save one command (after rebase the merge will resolve to a fast-forward anyway):

git rebase master feature
git checkout -B master
git branch -d feature

But better use aliases as others have suggested or don't rebase at all, simply merge

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文