Question

I'm trying to commit an automatic "build" file when doing a regular git push. So far I've tried to add the following to my git pre-push hook:

git add build.js
git commit -m "automatic build file"

It works in a sense that the push goes through, and I see 2 commits as expected: one is whatever I previously committed, and another is the one from the hook: "automatic build file".

The problem is when I do git status immediately after the push, I see the following:

Your branch is ahead of 'origin/master' by 1 commit.

Even though this is a little strange (because when I git checkout staging and git merge master, I see the automated commit there as well). When I remove the hook and do a git push in master after that, I don't think anything changes - it just fixes my local branch and the message is gone.

Is there a more proper way to sneak in an automated commit before the push? Or if I'm already doing it the right way, how do I get rid of the message?

Était-ce utile?

La solution

It is possible this is a side-effect of how git pre-push hook has been implemented:
See commit ec55559.

The list of commit that will be pushed is computed before your extra commit is generated.
So, it doesn't push your extra-commit, and your "git checkout staging/git merge" doesn't prove anything, because it is a local operation.
That means your local branch is indeed ahead by one commit of the upstream branch.

Note that you can do an alias which would call:

git push
git push --no-verify

The second push would not call the pre-push hook, and push your extra commit created by the first one.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top