gitpractice.dev

brewly — Ch.9 · Where did that code go?

Exercise 2 of 5

Before you start

Searching the changes themselves

git log -S <text> finds the commits where the number of times a text appears changed: where it was added, and where it was removed.

-p shows each commit’s changes under it, and --stat just the files. git show <commit> does the same for one commit.

Once you know the guilty commit, git revert undoes it.

git log --oneline -S <text>
commits that added or removed it
git log -p -S <text>
the same, with the changes
git show <commit>
one commit with its changes
git revert <commit>
undo it with a new commit
You can reopen this any time with “Lesson”.

Continue on a desktop

Typing git on a small screen is no fun. Open this page on a laptop or desktop to practise.

Back to the path