Name

reflog

Synopsis

git reflog show [branch]

Show entries from the reflog, which tracks changes to local refs (branches). If branch is omitted, shows the reflog for HEAD.

The reflog tracks the “history of history.” Although commands like git reset can be used to undo a commit, the old commit still stays around in the reflog until it eventually expires. This allows you to undo many Git operations you might have performed by accident.

You can refer to entries in the reflog using branch@{n} notation. For example, HEAD@{5} means to use HEAD as it existed five changes ago.

Examples

To list all the recent changes to HEAD:

$ git reflog

To undo the most recent merge operation:

$ git reset HEAD@{1}

Get Linux in a Nutshell, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.