![]() ![]() To exclude B and C as well, you must add ^C to your list of stopping points. If you name E as a stopping point and G as the starting point, git rev-list will skip commits E, D, and A, but will still include commits B and C, because those are reachable from F. C points back to B, which points back to A E points back to D, which also points back to A. So F points back to both E and C here, because F here is a merge commit. The arrows connecting commits (which I've been drawing as lines here) are all one-way: they all point backwards in time. This reachability notion is very important in more complex graphs: B-C You can name stopping-point commits in many ways, but the most direct is the hat-prefix: ^E means stop at E, or any commit reachable from E. You can tell git rev-list to start at G (by hash ID, or by name), but to stop (and not include) E (by hash ID, or by name if there's a name that points to E). You need to tell the Git commands that walk the graph where to stop. Adding -count makes it count them up, and there are probably many. The rev-list code does the same thing: you tell it where to start- $local_sha-and it lists that commit's hash, and its parent(s) hash(es), and more hashes of their parents, and so on. ![]() Since F has E as its parent, git log shows you E next, and so on. Then, since G has F as its parent ( G points to F), git log shows you F. ![]() You tell Git to start from branchname, which identifies commit G ( G here stands in for the actual 40-character hash ID), so git log shows you that commit. Git rev-list is the big brother (sister?) plumbing variant of git log: both will, by default, start from the commit(s) you give them, and find every commit reachable from those commits. You want git rev-list -count $local_sha ^$remote_sha (but see caveat below). #git commit -edit -m"$(git log -format=%B -reverse 0 Please squash your local branch before pushing." While read local_ref local_sha remote_ref remote_shaĬommits=`git rev-list -count "$local_sha"`Įcho "Multiple commits detected, push aborted. # Information about the commits which are being pushed is supplied as lines to # If pushing without using a named remote those arguments will be equal. # $2 - URL to which the push is being done # $1 - Name of the remote to which the push is being done # This hook is called with the following parameters: If this script exits with a non-zero status nothing will be pushed. # push" after it has checked the remote status, but before anything has been # An example hook script to verify what is about to be pushed. So I've tried the following pre-push git hook but even when I squash first it still thinks there are multiple commits. I want to force others to squash their feature branch commits before pushing and creating a pull request. I'm not sure if I'm going about this the correct way. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |