I\'m writing a pre-receive hook to do some validation before accepting commits on the push. It works fine with existing branches since I use following git command to get a list
More simply, you can use this:
git rev-list $new_sha1 --not --all
It's quite the same principle as in Aristotle Pagaltzis' answer, but it just uses rev-list
's built-in options (which I guess were added after this question was answered...).
The --all
parameter is equivalent to the for-each-ref
part: it adds all known refs to the command args. The --not
parameter, in this particular case, is like adding the ^
prefix to all refs added by --all
.
Thus this command will print commits reachable from the new SHA1 except all those reachable from the known (i.e. already pushed) refs.