Back

Explore Courses Blog Tutorials Interview Questions
+4 votes
2 views
in DevOps and Agile by (29.3k points)
edited by

There is a file that was being tracked by git, but now the file is on the .gitignore list.

However, that file keeps showing up in git status after it's edited. How do you force git to completely forget about it?

1 Answer

+4 votes
by (50.2k points)
edited by

To stop tracking a file you need to remove the file from index.

For removing a file from the index:

git rm --cached<file>

Note: This command will not delete a physical file in local it will delete the file from other developers from the next $git pull command.

Also, you can go with the following commands

git rm -r -- cached.

git add .

Then commit the file with -am then the file gets updated and then the file cannot be tracked.

.gitignore will prevent untracked files from being added so instead of .gitignore you can remove the file from the index so that the file cannot be tracked.

For better understanding about these commands go through the following crash course on git that will help you to understand git well

Browse Categories

...