Git reflog is a command that displays a log of all the Git reference updates made in the repository, including the HEAD and branch positions. It’s useful for recovering lost commits or branches that were accidentally deleted. The output shows the SHA-1 commit hash, the action performed (e.g., checkout, reset), the reference name, and a description of the change.
Here’s an example output from running git reflog
:
4d61b76 (HEAD -> master) HEAD@{0}: commit: Update README
6a5f29c HEAD@{1}: checkout: moving from feature-branch to master
2abb8f3 HEAD@{2}: commit: Add new feature
6a5f29c HEAD@{3}: checkout: moving from master to feature-branch
4d61b76 (HEAD -> master) HEAD@{4}: commit: Fix bug in user login
This output shows five recent updates to the HEAD position and branch positions in the repository. The most recent update was a commit made on the master branch. Before that, the HEAD was moved from the feature-branch to the master branch with the checkout action. Two more commits were made on the feature-branch before switching back to the master branch again.