Git append the current commit hash to result of a commit command
Domanda
I want to append the hash of the ongoing commit to its result. I can retrieve the hash using this command:
git log --format=%H | tail -1
Then I try to merge a commit with command above and make an alias in '.gitconfig', like this:
[alias]
ci = !git commit && git log --format=%H | tail -1
But this does not work; parameters of alias are send to tail command, not git commit.
How should I create this alias?
Soluzione
ci = !sh -c 'git commit "$@" && git log --format=%H | tail -1' --
You can find more info here
Also this is a more optimal way to get the hash of the last commit:
git log -1 --pretty=format:%H
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow