0

I don't get this behaviour

git status
...
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   ansible.log

while

me@rhel8:~/repos/ansible_get_postgres_version> cat .gitignore 

ansible.log
*.log
*.out

so, apparently the .gitignore is not effective when in comes to the ansible.log file.

However, .gitignore is not completely ineffective

echo "hello gitty" > test_this.out creates such a file but that is not shown as new to git with a git status (so, it actually is ignored).

One condition I could imagine as being the culprid is the fact that maybe the .gitignore did not exist before the ansible.log file got created. It that is the case ... what would I have to do in order to get it to being ignored by git as intendet?

phd
  • 82,685
  • 13
  • 120
  • 165
vrms
  • 217
  • 2
  • 8
  • added `another.log` file which also is being ignored, so my suspicions seems to be correct. Leaves me with the question on how to getting the `ansible.log` file to being ignored as well. – vrms Jul 25 '22 at 12:40
  • 1
    `.gitignore` applies to *untracked* files; it is not intended to ignore changes to tracked files. `ansible.log` has already been added to your repository. – chepner Jul 25 '22 at 12:42

1 Answers1

2

What you could try is using git rm --cached ansible.log that way the file is removed from the repo (unversioned). As long as it is versioned, it will show up in git status

Kevin
  • 1,068
  • 5
  • 14
  • 16
  • thx @Kevin ... what does _"versioned"_ precisely mean in this context? – vrms Jul 25 '22 at 12:50
  • 1
    @vrms I mean with that, that it is being tracked by git. So git will keep track of changes (versions) for that file. The proper term would have been "tracked" instead of versioned – Kevin Jul 25 '22 at 12:53