• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (deprecated)
You are here: Home / Computing / Set Number of Characters in Commit Hash for git log

Set Number of Characters in Commit Hash for git log

Last updated on December 6, 2023 by Sal Ferrarello

When I’m writing examples, it is often nice to have very short commit hashes. The --abbrev=4 argument, passed after the --oneline flag, allows me to reduce the number of characters in the commit to 4.

git log --oneline --abbrev=4

Output

6f5d (HEAD -> main) Add d.txt
e45b Merge branch 'feat/c'
330c Add c.txt
c145 Add b.txt
f6c7 Add a.txt
8044 Initial commit

Typically, I also want to use the --graph flag.

git log --oneline --graph --abbrev=4

Output

* 6f5d (HEAD -> main) Add d.txt
*   e45b Merge branch 'feat/c'
|\
| * 330c Add c.txt
|/
* c145 Add b.txt
* f6c7 Add a.txt
* 8044 Initial commit
Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP and JavaScript developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a principal engineer.

Filed Under: Computing, Dev Tips Tagged With: Git

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2026 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in