To remove files from stage use reset HEAD where HEAD is the last commit of the current branch. This unstages the file but maintain the modifications.
git reset HEAD <file>
To revert the file back to the state it was in before the changes we can use:
git checkout -- <file>
To remove a file from disk and repository, use
git rm. To remove a directory, use the
git rm '*.txt' git rm -r <dirname>
If we want to remove a file from the repository but keep it on disk, say we forgot to add it to our
.gitignorefile then use
git rm <filename> --cache
Help & feedback
DocsEdit this page to fix an error or add an improvement in a merge request.
Create an issue to suggest an improvement to this page.
ProductCreate an issue if there's something you don't like about this feature.
Propose functionality by submitting a feature request.
Join First Look to help shape new features.