HASH=`git rev-parse HEAD`

cd /home/dq/chatbot
HASH=git rev-parse HEAD
HASH2=git rev-parse HEAD~1
git --no-pager diff $HASH2 $HASH

Hello!

I’ve tried to understand this part:

HASH=git rev-parse HEAD
HASH2=git rev-parse HEAD~1

After looking at different sources on the web, I still can’t understand what this part of the code is doing.

Can somebody explain? Would be really appreciated.

Thank you!

1 Like

git rev-parse is short for git revision-parse . It takes the given input and returns the corresponding 40-character revision ID.

You can view the full 40-character revision ID using git log.

git rev-parse HEAD gives the commit 40-character revision ID that HEAD is pointing to.

git rev-parse HEAD~1 gives 40-character revision ID belonging to the 1 less commit before HEAD. The commit before HEAD.

HASH=git rev-parse HEAD

Assigns variable HASH to git rev-parse HEAD. git rev-parse HEAD gives the HEAD’s commit 40 character revision ID. HASH = 40 character commit revision ID belonging to the current HEAD.

HASH2=git rev-parse HEAD~1

Assigns variable HASH2 to git rev-parse HEAD~1. git rev-parse HEAD~1 gives the 1 commit before HEAD’s 40 character revision ID. HASH2 = 40 character commit revision ID belonging to 1 commit before HEAD.

From stackoverflow:

--no-pager to Git will tell it to not use a pager. Passing the option -F to less will tell it to not page if the output fits in a single screen.

Usage:

git --no-pager diff

Other options from the comments include:

# Set an evaporating environment variable to use 'cat' for your pager
GIT_PAGER=cat git diff

# Tells 'less' not to paginate if less than a page
export LESS="-F -X $LESS"
# ...then Git as usual
git diff
3 Likes