git:分支更改时快进切换的钩子?

发布于 2024-12-18 21:07:24 字数 353 浏览 2 评论 0原文

是否有可用的钩子脚本可以在分支切换上进行快进合并?我有一个存储库,其中有多个分支,我必须在其中几个分支上工作。在 git pull 显然合并了当前签出的分支之后,我经常会在切换分支时看到以下消息:

> git checkout master 
Switched to branch 'master'
Your branch is behind 'origin/master' by 10 commits, and can be fast-forwarded.
> 

我希望 git 在分支更改时自动为我进行快进合并。我不希望它无条件合并,但仅当可以快进时才合并。

预先感谢您的建议,
朗达

Is there a hook script available somewhere that would do a fast-forward merge on branch switch? I have a repository where there are multiple branches, and I have to work on several on them. After a git pull which obviously merges the currently checked out branch it often happens to me that I see the following message when switching branches:

> git checkout master 
Switched to branch 'master'
Your branch is behind 'origin/master' by 10 commits, and can be fast-forwarded.
> 

I would like git to do that fast-forward merge for me automatically on branch change. I don't want it to unconditionally merge but only when a fast-forward is possible.

Thanks in advance for suggestions,
Rhonda

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

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

发布评论

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

评论(1

始于初秋 2024-12-25 21:07:25

我建议使用别名而不是挂钩,以便将

  • git pull
  • 与“如何以编程方式快进单个 git 提交?”中详细介绍的脚本之一 结合起来。 (但为了快进而进行了调整)

问题“当我希望我的分支始终更新时使用 Git”引用脚本“git-fetch-and-fast-forward-all-branches.sh”,这里可能很有趣。

I would suggest an alias rather than a hook, in oder to combine:

  • git pull
  • with one of the scripts detailed in "How can I fast-forward a single git commit, programmatically?" (but adapted in order to fast-forward all the way)

The question "Using Git when I want my branches to be always updated" references the script "git-fetch-and-fast-forward-all-branches.sh", which can be of interest here.

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