Your Git Commit History with Git Log and Reflog commands |Video upload date:  · Duration: PT1M0S  · Language: EN

Learn how to inspect and recover commits with git log and git reflog use concise views and safe recovery tips for repositories

If your commit history looks like a crime scene and you are missing a few suspects do not panic yet. Git keeps a trail of where HEAD and branches have been and with a few commands you can read the story or even resurrect a missing commit. This guide helps you inspect history with git log and find recent moves with reflog so you can recover work without becoming the office cautionary tale.

See the basic commit trail

Start with the obvious. Run the plain command to list commits with author date and message. It gives a readable timeline for most needs.

git log

If you want a slightly friendlier view add options to limit output or show diffs for a commit. But the default is where you begin looking.

Make busy history readable

When the commit graph looks like someone tried to knit spaghetti use a compact visual view. The following shows each commit on one line with branch names and a nice ASCII graph which works in terminals and in automation logs.

git log --oneline --graph --decorate --all

This helps you spot the current HEAD branch and merges fast. It also plays nicely when you are on GitHub or GitLab and want to match UI history to what is on your machine.

Find recent moves with reflog

The reflog is the safety net that remembers where HEAD and refs pointed recently even after resets or forced pushes. It is not a permanent record but it is incredibly useful for short term rescue missions.

git reflog

Scan the list for the commit hash you want to recover. Each line shows an action such as checkout reset or commit along with the hash and a human friendly note.

Recover a commit without tears

Once you have the hash you can either make a branch from it or move a branch pointer. Making a branch is the safest and least dramatic option.

git checkout -b rescue abc1234

That creates a branch named rescue at commit abc1234 so the commit is easy to work with and can be pushed to remote for safe keeping. If you prefer the newer command use

git switch -c rescue abc1234

If you need to rewind the current branch and you are certain of your choice you can reset hard. Do not do this without a backup branch unless you enjoy adrenaline.

git reset --hard abc1234

Practice safe cleanup

Git eventually prunes unreachable objects during garbage collection. That means reflog and dangling commits may disappear after some time. Keep important recovery points on a branch or a tag so the reflog is a helper not the only lifeline.

  • Create a branch from the current HEAD before risky operations
  • Push that branch to the remote repository on GitHub or GitLab if you need offsite backup
  • Use soft or mixed reset if you want to keep changes staged or in the working tree

Quick command summary

  • git log to inspect full commit information
  • git log --oneline --graph --decorate --all for a compact visual overview
  • git reflog to view recent HEAD and ref moves
  • git checkout -b rescue abc1234 or git switch -c rescue abc1234 to restore a commit
  • git reset --hard abc1234 only after making a backup branch

If you follow these steps you will spend less time apologizing in team chat and more time writing code. Or at least less time rewriting history by accident. Keep branches and tags for the commit you care about and treat reflog as a fast rescue tool not a permanent insurance policy.

I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!

This is a dedicated watch page for a single video.