Search⌘ K
AI Features

Lose a Commit, Get it Back

Understand how to recover lost commits with Git reflog. This lesson teaches you to track repository changes, manipulate branch history, and restore prior commits using git reset. Gain practical skills to manage repository states even after commits disappear from branches.

Add commits

First, set up a repository with two commits:

1	mkdir lgthw_reflog
2	cd lgthw_reflog
3	git init
4	echo first commit > file1
5	git add file1
6	git commit -m "first commit"
7	echo second commit >> file1
8	git add file1
9	git
...