Advanced Git Commands
git log
: View commit details
git log
: View commit detailsSample output of git log. Use j
and k
on the keyboard to scroll up and down and q
to exit the log view.
Each log entry will describe what that commit does. Each commit will have a commit hash, author and date.
For example this commit:
commit hash is
f5458f36c67c927fcd41e65e29eb5b8a1491d7a1
author is
francisyzy <francisyzy@me.com>
which was set by the author'sgit config
date of the commit is
Fri May 17 17:14:09 2024 +0800
message of the commit is
Update links
The git commit history is also viewable on the Github repository itself.
git revert
: Revert a commit
git revert
: Revert a commitLets you 'undo' a commit. It will undo the changes made by that commit and make a new commit to do so.
Do note that this is not the method of removing sensitive information as commit history can still retrieve it.
There is a stackoverflow discussion on how to remove such information and rewrite history. Do note that rewriting history will result in other people's repo being broken.
git reset
: Reset HEAD to the commit
git reset
: Reset HEAD to the commitThis will reset the current HEAD to the commit hash.
Useful reset command that can be used to edit the commit message before its being pushed to the remote is: git reset --soft HEAD~
. The command will reset the files to the commit right before the current commit and leave the files in the latest commit in staged. Allowing you to git commit -m "Updated message"
to change the git commit message.
git checkout
: Checkout files (and also a branch) commits
git checkout
: Checkout files (and also a branch) commitsYou can also use git checkout <commit hash>
to go to view the files at a specific commit too.
A useful feature to have when you want to check out the files of that commit before you reset to that commit.
Last updated