568
Julia Evans' Git cheat sheet
(programming.dev)
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Follow the wormhole through a path of communities !webdev@programming.dev
In recent git versions (>2.23),
git restore
andgit restore --staged
are the preferred ways to discard changes in the working tree (git checkout -- .
) and staged changes (git reset --
) respectively.Huh, TIL.
To be fair,
git switch
was also derived from the features ofgit checkout
in >2.23, but likegit restore
, the manual page warns that behavior may change, and neither are in my muscle memory (lmao).I'll probably keep using checkout since it takes less kb in my head. ~~Besides, we still have to use checkout for checking out a previous commit, even if I learn the more ergonomically appropriate
switch
andrestore
.~~ No deprecation here so...edit: maybe I got that java 8 mindset
edit 2: Correction --
git switch --detach
checks out previous commits. Git checkout may only be there for old scripts' sake, since all of its features have been split off into those two new functions... so there's nothing really keeping me fromswitch
.git switch works on commits too. I don't think you have to use checkout anymore.
Oh, you're right. You just pass the
-d
detach flag. I stand corrected!