git reflog
git
Usage
git reflog [show] [<ref>]Remembers every position HEAD and your branches have had, which is where commits lost to reset --hard or a deleted branch turn up; entries expire after 90 days by default and exist only on your machine.
Common flags
| Flag | Meaning |
|---|---|
| show <ref> | the positions of one branch instead of HEAD |
| --date=iso | real timestamps instead of relative ones |
| -n <n> | only the last n entries |
| HEAD@{n} | the commit HEAD pointed at n moves ago |
| expire --expire=now --all | wipe the log, which also gives up the safety net |
Examples
git reflogevery position HEAD has had, newest first
git reflog --date=iso -n 20the last twenty moves with real dates
git reset --hard HEAD@{1}undoes the reset you just regretted
The confusion is that undo has several shapes — moving where a branch points is not the same as adding a commit that reverses it.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does git reflog do?
Remembers every position HEAD and your branches have had, which is where commits lost to reset --hard or a deleted branch turn up; entries expire after 90 days by default and exist only on your machine.
Q. How do I type it?
git reflog [show] [<ref>] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
5 are listed here; the full set is in man git. This command sits under git.
Related commands
man page: man git-reflog