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.
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.
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.
When a commit looks lost follow these practical steps without panicking.
git reflog
to find the commit hash you want.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.
git log --oneline --graph --all
Show compact history across branchesgit reflog
List every local update to HEAD and refsgit checkout -b recover HASH
Rescue a lost commit onto a new branchgit reset --hard HASH
Move current branch to a commit and discard working stateReflog 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.
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.