Unstage a file in Git
When you stage a file in Git, you instruct Git to track changes to the file in preparation for a commit. To disregard changes to a file, and not include it in your next commit, unstage the file.
Unstage a file
-
To remove files from staging, but keep your changes:
git reset HEAD <file>
-
To unstage the last three commits:
git reset HEAD^3
-
To unstage changes to a certain file from HEAD:
git reset <filename>
After you unstage the file, to revert the file back to the state it was in before the changes:
git checkout -- <file>
Remove a file
-
To remove a file from disk and repository, use
git rm
. To remove a directory, use the-r
flag:git rm '*.txt' git rm -r <dirname>
-
To keep a file on disk but remove it from the repository (such as a file you want to add to
.gitignore
), use therm
command with the--cache
flag:git rm <filename> --cache