阻止将简单合并推送到 git 服务器
不久前,我 要求我们的开发人员使用 rebase 而不是在推送之前合并。消除琐碎的合并使得更容易遵循提交图(即:gitk、git log)。
有时人们仍然会不小心进行简单的合并,然后推送。有谁有编写阻止简单合并的服务器端挂钩的方便或技巧吗?
我所说的“简单合并”是指没有冲突的合并。 这是一个示例 和 这是 git 中简单合并的更好解释< /a>.
2010 年 11 月 10 日星期三 01:26:41 UTC 更新:大家都发表了精彩的评论!谢谢。
- 考虑以下几点:我真正要求人们做的是:
- 如果
git pull --ff-only
失败,请执行git pull --rebase
而不是git pull
- 如果
- git.git 仅具有一两个提交者,对吧?理论上,遵循提交图应该很容易,但对我来说它看起来很混乱。
2010 年 11 月 11 日星期四 23:49:35 UTC 更新:
- 这里有一些要点 -进度工作
- 另一个想法是通过“git推送”来防止客户端上的琐碎合并包装器
UTC 2010 年 12 月 15 日星期三 18:34:52 更新:
A while back I asked our developers to use rebase instead of merge before pushing. Eliminating trivial merges makes for a much easier to follow commit graph (ie: gitk, git log).
Sometimes folks still accidentally do trivial merges, then push. Does anyone have handy or have tips for writing a server-side hook that blocks trivial merges?
By "trivial merge", I mean a merge without conflicts. Here's an example, and here's a better explanation of a trivial merge in git.
Update Wed Nov 10 01:26:41 UTC 2010: great comments, all! Thank you.
- Consider the following: all I'm really asking folks to do is this:
- if
git pull --ff-only
fails, dogit pull --rebase
instead ofgit pull
- if
- git.git only has one or two committers, right? In theory, it should be easy to follow the commit graph, but it looks pretty messy to me.
Update Thu Nov 11 23:49:35 UTC 2010:
- here's a gist with some in-progress work
- another idea is to prevent trivial merges on the client end, with a "git push" wrapper
Update Wed Dec 15 18:34:52 UTC 2010:
- adymitruk is close! Just one case is still unresolved: non-trivial merges must still work.
- A rather complete test suite is available, check it out.
- I asked for help on a (the?) git mailing list.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在尝试寻找解决方案时遇到了这段代码。它并不完全符合您的要求,但应该可以在 if 语句上添加额外的分支名称。
到目前为止,对我有用。它强制对同一分支进行 pull --rebase 并允许与其他分支进行常规合并。
所有学分均归原作者所有。
I came across this piece of code, while trying to find a solution. It doesn't do exactly what you want, but it should be ez to add extra branch names on the if statement.
Works for me, so far. it forces pull --rebase for the same branch and lets regular merges with other branches go through.
All credits go to the original author.
这个更新挂钩将检查您是否正在推送到特定分支(它允许在 wip、主题和其他分支中进行简单合并)。
这不会影响 octopus 合并上的其余父级,因为它只引用正在推送的每个合并提交中的第二个父级。请随时更新脚本。
更新:远程设备上需要存在保留分支。
This update hook will check if you are pushing to specific branches (it allows trivial merges in wip, topic and other branches).
This does not bother with the rest of the parents on octopus merges as it only references the 2nd parent in each merge commit being pushed. Please feel free to update the script.
UPDATE: Reserved branches are required to exist on the remote.