The .gitignore file .gitignore not mean what you think it means. 1
In particular, once you have made the file "known" on git, as it adds in the index that the .gitignore file name is not valid. Git is already tracking the file, and it will continue to track it.
In essence, a .gitignore file is .gitignore actually a list of files to ignore. Instead, when Git encounters an "untracked" file and is about to let you know, the contents of .gitignore is a list of names that it should suppress.
For the .gitignore file .gitignore you probably just want git add to make changes and commit them, because as a rule, any clone of your repository probably wants to ignore the same set of raw files, so .gitignore needs to be tracked and versioned.
However, for the XML file, there may be “generated content” that you do not need for version control, but you still want to save it in the tree. This is a bit of a problem because Git is already tracking it and will insist on continuing version control with the file.
What you can do at this point, remove it from the Git index, but not from the tree:
git rm --cached mllib/pom.xml
This is as fine as possible (git removes the file from the index, and the next commit does not have this file), but it creates problems if you ever return to a commit that has the file, because Git will see what it needs to create file - you switch from a commit in which the file does not exist (the last) to a commit in which it exists (the old), and may complain that the contents of this file will be dropped. Or, even if this part works, if you go to the latest version, leaving the old version, Git will compare the old and new versions and see that the file has been deleted ... and delete mllib/pom.xml .
Edit, October 20, 2016 . Use git update-index --skip-worktree , not git update-index --assume-unchanged . This sets a more powerful bit in the index. See Git - The Difference Between Assume-No-Change and Skip-Worktree . Edit : as Schwarn noted in the comment below , you can use git update-index --assume-unchanged to make Git even without looking at the file for changes, and not use git rm --cached to get it out of the index (for more details see this answer ). It is as beautiful as possible, you just need to do it again (or all your employees will do it themselves) on any other / new clones.
(You can restore it with git show <oldrev>:mllib/pom.xml > mllib/pom.xml to upload the file to standard output and redirect standard output to re-create the file.)
1 Incomprehensible!
(More seriously, everyone makes this mistake. Probably gitignore was the wrong name, and something like git-screen-away-untracked could be better if klunkier. However, listing the file in .gitignore also has other side effects: in particular allows Git to collect such files in some cases.)