27%
Oops - How to Undo Anything
Everyone makes mistakes. You'll edit the wrong file, commit something you didn't mean to, or just want to go back to how things were five minutes ago. Git has several tools for these situations, and knowing them will save you a lot of stress.
Previously, you learned that files move through three areas: Working Directory β Staging Area β Repository. The undo commands in this chapter move files in the opposite direction, depending on which step you want to reverse:
Working Directory Staging Area Repository
ββββββββββββββββββββ ββββββββββββββββ βββββββββββββββββββββββ
β β β β β β
β your edits β<ββββββ staged β<ββββββ committed β
β β β changes β β snapshots β
ββββββββββββββββββββ ββββββββββββββββ βββββββββββββββββββββββ
β β β
β git restore β git restore --staged β git revert
β (discard edits) β (unstage, keep, edits) β (new commit that
β β β reverses a
v β β previous one)
last commit v v
version back to new "undo"
working dir commit
Learn Git in a Day
Everything you need, nothing you don'tEnroll now to unlock all content and receive all future updates for free.
Unlock now Β $9.99$7.49Learn More
Hurry! This limited time offer ends in:
To redeem this offer, copy the coupon code below and apply it at checkout:
