What does git rm --cached do?

What does git rm --cached do?

a) Removes a file from the staging area but keeps it in the working directory
b) Deletes a file from both the staging area and working directory
c) Moves a file to a new location
d) Reverts the last commit

Answer:

a) Removes a file from the staging area but keeps it in the working directory

Explanation:

The git rm --cached command removes a file from the staging area but keeps it in the working directory. This unstages the file, preventing it from being included in the next commit, but the file itself remains in your local directory.

For example, running git rm --cached filename will untrack the file but keep it in the project directory.

This command is useful when you want to remove files from version control without deleting them locally.

Reference:

Top 100 Git and GitHub MCQ Questions and Answers

Scroll to Top