Module 2 · Git: the 20 everyday commands · Lesson 14 of 16
Undo safely: reset, revert, checkout and tag
Unstage files, drop local commits, reverse shared ones, throw away edits, and mark releases.
In this lesson · about 24 minutes
- Unstage a file with git reset FILE
- Drop commits that were never pushed with git reset (and know --soft, --mixed, --hard)
- Undo a commit others already have with git revert
- Discard edits to a file with git checkout -- FILE, and mark releases with git tag
Key terms
Say the meaning to yourself, then tap a card to check.
Sorting drill
reset or revert?
Has anyone else got the commit? That decides it.
- Undo a commit you made 5 minutes ago and have not pushed
- Undo a commit that is on GitHub and your team has pulled
- Take a file off the staging area
- Back out a bad release that is already live
0 of 4 sorted
Practice terminal · missions
A messy morning: clean it up without losing anything
Sam accidentally staged a secrets file, has a half-done holiday banner, an unpushed debug commit, and an already-pushed commit that switched prices to euros by mistake. Fix it all.
Missions 0 of 13
- 1Look at the status.
- 2Take secrets.txt off the staging area.
- 3Delete secrets.txt from the folder.
- 4Park the unfinished banner work in the stash.
- 5Look at the history, one line each.
- 6Drop the unpushed debug commit completely.
- 7Undo the pushed 'Switch prices to euros' commit the safe way.
- 8Bring the banner work back out of the stash.
- 9Oops: echo "junk" > README.md (this overwrites the file!)
- 10Throw away the change to README.md.
- 11Commit the finished banner.
- 12Tag this commit as release v1.1.
- 13Push your commits and your tags.
Type a command and press Enter. Try help to list commands. Tab finishes names, ↑ repeats.
Repository ~/website · on main
1 · Working folder
The files you edit
- README.mdsaved
- index.htmlchanged
- prices.txtsaved
- secrets.txtsaved
- style.csssaved
2 · Staging area
Packed for the next commit
- secrets.txtnew
3 · Commit history (this computer)
Each dot is a saved snapshot. Labels are branches, tags and what you last heard from origin.
☁ Remote: origin
https://github.example/sam/website.git
- maina847c43Switch prices to eurosbehind you
Check your understanding0 of 4 correct
Quiz score: 0 of 4
Written by Noviq Academy in its own words. The practice terminal is a simulation that runs in your browser: it imitates Linux (Ubuntu-style output) and Git closely, but it is not a real computer, and real output can differ slightly. The servers, people, web addresses and GitHub addresses in the labs are made up. Linux is a trademark of Linus Torvalds; Git and GitHub belong to their owners. Read-aloud uses your device's built-in voices.