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.env

Related terms

Taught in

References