Does git rm delete the file?
tldr; Yes. Yes it does. (use git restore --staged <filename>
to un-delete if you made that mistake*)
Does git rm <file/path name>
remove the file? How to find out yourself: See man git rm
or read on.
Sometimes you find git is tracking files (e.g. binary files like images) which you shouldn't be tracking. Git is for tracking text not blobs like images/bins.
Whilst you can't remove them easily - you can tell git to stop tracking them with thegit rm --cached
option.
How to tell git to stop tracking previously tracked files
If you just want to stop git from tracking some files or a directory, then use:git rm --cached <filename>
this will stop git from tracking the file and "remove it from the index" without removing the file.
You probably then want to add the file(s)/path to your .gitignore
file to prevent them from being tracked.
*There's no such thing as 'deleting' a commit in git
Sometimes you mistakenly commit files to the git repo which you don't want to track. There's no easy way back from this if you've pushed (and that's the whole point- git works very hard to ensure once committed you can always get the exact file tree back. Shockingly, not all version control systems give you that guarantee (see Linus's biased tech talk on the matter).
But I really do want to remove large files from git, how to I do that?
Yes. You have two options the built-into-git feature git filter-branch
or BFG Repo-Cleaner.
Are you trying to remove password committed by mistake? Don't bother. Change the password. The cat is out the bag.
I want to learn more
Consider buying "Oh shit, git!" by Julia Evans and listening to Linus's tech talk explaining his design for git.