git rm
The command that removes a file from the staging area, and from disk unless you add --cached, so the next commit stops tracking it.
In more detail
git rm --cached service.env untracks a file you committed by mistake while leaving it on disk; commit that, and add it to .gitignore so it stays untracked. Untracking changes only the future: every earlier commit still contains the file.
Example
git rm --cached service.envRelated terms
- tracked file — A file Git already knows about because it is in the last commit or the staging area; any other file is untracked.
- .gitignore — A text file of patterns naming untracked files Git should not report or add, such as build output and logs.
- leaked secret — A password, token or key that has been exposed, for example by being committed to a repository, and must be treated as known to others.
- rm — The command that deletes files, and with -r whole directory trees, permanently.
Taught in
- Ignoring Files, And The Tracked File Trap — Advanced Git Internals & Distributed Workflows