Git- Why .txt file is not ignored

10,545

Solution 1

If you've ever committed the text file git is already tracking it. You need to remove it from git so that it will be untracked, then it will properly ignore it.

git rm --cached name.txt

Solution 2

You probably already committed the file so it is tracked. You need to:

git rm --cached filename

Solution 3

Gitignore does not stop you from tracking already tracked files. You need to remove them from your repo.

find . -name '*.txt' ¦ xargs git rm

Should do the trick.

Solution 4

I think you have added that .txt file in the staging index before including .txt in the .gitignore file. To untrack it, you have to remove that .txt file from the staging index. To remove it from staging index but not from working directory, paste the following line:

git rm --cached my_file.txt

If it does no work then paste:

git rm --cached my_file.txt -f

Solution 5

Another possible error is to have white space after the *.txt line.

Share:
10,545
marco
Author by

marco

Updated on June 11, 2022

Comments

  • marco
    marco almost 2 years

    I need to ignore .txt file in git. To do so i have included *.txt in the .gitignore file.But when i edit something in one of my .txt file git is still tracking it. Where is the problem or do i make something wrong. Please help me.

  • Jordan
    Jordan over 3 years
    Yeah, this doesn't seem like the solution at first glance, but it really is. Git will not ignore any file it is already tracking. Will this help if the file has already been added to the repository?
  • Ryan Poolos
    Ryan Poolos over 3 years
    Yea it will help if the file is already added to the repo but you'll have to git add . and commit so that it gets committed as deleted.