Menu
Newbedev LogoNEWBEDEV Python Javascript Linux Cheat sheet
Newbedev LogoNEWBEDEV
  • Python 1
  • Javascript
  • Linux
  • Cheat sheet
  • Contact

How to get first 5 chars of a git commit hash id and store it in a variable in bash?

Using --short option:

$ git rev-parse --short=5 HEAD
90752

$ x=$(git rev-parse --short=5 HEAD)
$ printf '%s\n' "$x"
90752

The cut utility should do what you want.

$ x=$(git rev-parse HEAD | cut -c1-5) && echo $x

Why one line?

Tags:

Git

Bash

Related

Why can't mv deal with existence of same-name directory in destination? bash / sh script to replace text between some tags/strings in a text file How do you make filesystems in mac OSX How can I activate extra-verbose mode (debugging mode) during Debian boot? Linux Audio Spectrum Analyser Run the same command multiple times in background How can I access the history buffer in sh? (not in Bash) Setting persistent environment variable in CentOS 7 issue Insert text at specific line number Running dd. Why resource is busy? How to set ctrl+c to copy, ctrl+v to paste and ctrl+shift+c to kill process in xfce4-terminal? Remove file, but only if it's a symlink

Recent Posts

Pandas how to find column contains a certain value Recommended way to install multiple Python versions on Ubuntu 20.04 Build super fast web scraper with Python x100 than BeautifulSoup How to convert a SQL query result to a Pandas DataFrame in Python How to write a Pandas DataFrame to a .csv file in Python
© 2021 newbedevPrivacy Policy