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-onlyfails, dogit pull --rebaseinstead 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.
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.