Reputation: 81
I am working on a git pre-push update hook wherein I would like to check for a specific condition in a commit only if there is no merge commit associated with it. In case there is a commit with an associated merge commit, then I would like to skip checking the individual commit and check the merge commit instead.
In order to be able to do this, I would need to have the exact list of commits associated with a merge commit so that I can filter them out from the commit list which inturn contains the total list of commits getting pushed to remote.
Is there a git command/option to find the commit range merged in a Merge commit ?
For instance: I would like to get only the below highlighted text as the command output:
$ git log --merges
commit fd3d8c5bc3e689cf44b5ca1e8d06fe2a6bd02716
**Merge: f778e20 cefb2e9**
Author: abc <[email protected]>
Date: Mon Aug 17 22:00:49 2015 -0700
Merge branch 'feature_personal'
I attempted to do the following:
$ git log --pretty=%P -n 1
f778e20d1bfa0b1821d93feca3863a69af48de1f cefb2e96279447b2c268167a2db3605b84717de
This works well when you use -n 1 which is doable on the client side but does not work out as part of a git hook on the server side. Is there a way to use SHA id of the merge commit and get these details ?
I would also like to get all the list of commits included in the range f778e20..cefb2e9. This would give me the total list of commits associated with the merge commit.
I tried using git rev-list f778e20..cefb2e9 but this lists a lot of commits.
Any suggestions/thoughts ?
Upvotes: 4
Views: 3451
Reputation: 9413
You can use something like:
git log --oneline --merges <commit_hash_to> <commit_hash_from>
Below is the link to a question which provide details on choosing these hash (parents) to get clear range.
http://stackoverflow.com/questions/18679870/list-commits-between-2-commit-hashes-in-git
Upvotes: 2