9 | Undoing Uncommitted Changes |
Gitâs two-step process for tracking a commit means you can have
files that are staged for commit that youâre not ready to commit.
You use git reset HEAD
or
git rm --cached
depending on the
circumstance.
Scenario 1: You staged a change to a file and want to unstage
itâuse git reset HEAD
. This is the
most common use. Youâre telling Git, âChange the indexâthe
staging areaâto the latest version of this file.â
Scenario 2: You have a new file thatâs been staged that you donât
want to commit nowâuse git rm
--cached
. Normally, git
rm
is used to remove files from your repository, but
adding the --cached
option tells Git
to leave your working tree alone.
Another common problem is making changes ...
Get Pragmatic Guide to Git now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.