git log and reflog compared |Video upload date:  · Duration: PT9M44S  · Language: EN

Understand differences between git log and reflog and learn when to use each for history inspection and recovering lost commits.

If you broke something in Git and are now sweating quietly into your keyboard you are not alone. Git has two mostly friendly tools for poking at history. One shows the shared story you and your team agreed on. The other keeps a private diary of every time you told HEAD to do something dumb.

What git log shows

git log walks the commit graph reachable from a branch or reference. Think of it as the public ledger. Use options like git log --oneline or git log --graph to see a condensed, human readable overview. This is the history that gets pushed and reviewed in pull requests. If it is not in git log then other people do not see it.

What git reflog records

git reflog records local reference updates. That includes checkouts, rebases, resets and merges that moved HEAD. This is a personal safety net that remembers where HEAD has been even when those commits no longer appear in the public graph. It is local to your repo on disk so do not treat it as a permanent backup.

Common commit recovery workflow

When a commit looks lost follow these practical steps without panicking.

  • Run
    git reflog
    to find the commit hash you want.
  • Create a branch from that hash to avoid making things worse. Example
git checkout -b recover abc1234

If your goal is to move an existing branch back to the found commit you can do that too. Only run this when you are sure because it rewrites history.

git reset --hard abc1234

When in doubt create a branch first. Creating a branch is the difference between a safe museum exhibit and a crime scene.

Quick cheat sheet for common commands

  • git log --oneline --graph --all Show compact history across branches
  • git reflog List every local update to HEAD and refs
  • git checkout -b recover HASH Rescue a lost commit onto a new branch
  • git reset --hard HASH Move current branch to a commit and discard working state

Important caveats about reflog and safety

Reflog entries expire according to your garbage collection settings such as gc.reflogExpire and gc.reflogExpireUnreachable. If a commit matters push it to a remote or tag it so the commit moves out of the fragile local-only zone. Tags and remotes are the difference between permanent records and ephemeral notes scribbled on a Post it.

Final tip to avoid late night panic

If you do a mistaken reset or rebase run git reflog first and create a branch from the reflog hash you want. That preserves the work and helps you avoid furiously guessing commands while on adrenaline. Use git log when you want to inspect the shared history. Use git reflog when you want to recover a local action that no longer shows up in the shared history.

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.