Using Abbreviated Commits in Git

git commit abbreviated

1 min read | by Jordi Prats

To pin some code to a specific version we can use a commit ID instead of a tag but using such a long string might feel a tad cumbersome:

$ git log commit fb944d599d5487229463478928834cac20963f75 (HEAD -> main) Author: Eric <some@thing.com> Date: Wed Jun 7 20:27:17 2023 +0100  Fix exit with no error when cert violates lookahead (#2395) (...) 

Instead we can use an abbreviated commit, to get them we can either cut the firsr 8 characters of the commit ID or just use git log's option: abbrev-commit:

$ git log --abbrev-commit commit fb944d59 (HEAD -> main) Author: Eric <some@thing.com> Date: Wed Jun 7 20:27:17 2023 +0100  Fix exit with no error when cert violates lookahead (#2395) (...) 

This way we are going to get the short version of the commit ID.


Posted on 22/06/2023

Categories