I am using below git command to get last 2 commit hash
git log -n 2 --pretty=format:"%H" #To get only hash value of commit
But I needs only second last commit hash.
Any help would be great
Thanks
To pull up a list of your commits and their associated hashes, you can run the git log command. To checkout a previous commit, you will use the Git checkout command followed by the commit hash you retrieved from your Git log.
If you have the hash for a commit, you can use the git show command to display the changes for that single commit. The output is identical to each individual commit when using git log -p .
Hashes are what enable Git to share data efficiently between repositories. If two files are the same, their hashes are guaranteed to be the same. Similarly, if two commits contain the same files and have the same ancestors, their hashes will be the same as well.
git rev-parse @~
rev-parse turns various notations into hashes, @
is current head, and ~
is the previous commit.
This generalizes to commits arbitrarily far back: for example, you can write @~3
(or @~~~
) to specify "three commits before the current head".
Use skip
attribute--skip=<number>
skips number commits before starting to show the commit output.
git log -n 1 --skip 1 --pretty=format:"%H"
Follow this link for more info on git log
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With