Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting whole commit message of a reset commit

How do I get the whole commit message of a commit which I hard reset?

There could be a way to do it using git reflog, however, do we have another way?

like image 208
dhgoratela Avatar asked Sep 08 '26 19:09

dhgoratela


1 Answers

You could use git log -g to walk back through your previous HEADs, but it will not have information about why HEAD moved.

You could read the logs straight from .git/logs/HEAD. That won't show you anything git reflog won't, but it might be easier to develop a tool to find the IDs of resets.

git reflog will show all your previous HEADs (the commits you had checked out) in order and why HEAD moved. git reflog takes all the same options as git log. For example, you can get more context with git reflog --pretty=medium to see the full commit messages. However, it's probably easier to get the commit ID from git reflog and then the commit message with git log <that id>.

A reset should be easy to spot. For example, here is a git reset --hard HEAD^1.

70cc722 (HEAD -> master) HEAD@{0}: reset: moving to HEAD^1
5cbd5ea HEAD@{1}: reset: moving to HEAD
like image 200
Schwern Avatar answered Sep 11 '26 00:09

Schwern