Skip to content
GitTree

Video: Find a lost commit with reflog

The video plays in YouTube’s player, in privacy-enhanced mode.

Find a commit that a hard reset left behind in the local reflog, check its file before you trust it, and put a branch on it, without moving your current checkout.

Read the full lesson

The article has every step and command from the video, the practice exercise and the questions.

Go to the lesson

Video transcript

The narration of the video, cue by cue.

  1. A commit seems gone. Git still remembers where it was.
  2. The reflog is a local diary of where HEAD and branches have been.
  3. A commit no branch names can still be listed in it.
  4. In a disposable copy: commit a note, and then hard reset it away.
  5. The graph shows only M. The note is nowhere to be seen.
  6. Don't reset, or clean up, now. Look first.
  7. Open the palette, and run View Reflog.
  8. The dialog opens on HEAD. The newest move is first.
  9. The newest row is the reset. Just below it is the lost commit.
  10. If the list is long, show older entries.
  11. You can switch between HEAD and the branch.
  12. Don't memorize HEAD at one. Read the entry instead.
  13. Select the commit entry. New choices appear.
  14. Show in Graph cannot place it: no branch reaches this commit.
  15. So restore it as a branch first, then read its file.
  16. Go back, and select the same entry.
  17. Name the branch rescue slash signup.
  18. Restore it as a branch. The notice says undo removes it again.
  19. The rescue branch is on the lost commit. You are still on M.
  20. Your files did not change.
  21. In the terminal, the two newest lines are the reset and the commit.
  22. With IDs, we pick the commit by its line.
  23. git show with a path reads the file from that commit.
  24. git branch makes the rescue branch. Our checkout stays put.
  25. The status is empty, and the file is safe on the branch.
  26. An edit that was never committed is not in the reflog.
  27. Entries expire. Don't run cleanup while you recover.
  28. It is local. Other clones don't have your diary.
  29. Practice: report the lines, the ID, the first line, and the branch.
  30. Next, GitTree's own Undo and Redo.

All tutorials