1

I would like to ignore the changes that I do locally to the pom.xml and .gitignore files as I do them just for trial purpose but should never be committed and pushed in the company repository.
Obviously without an automatic mechanism to ignore them it is very easy to forget to revert back their changes and commit those together with the other files on which I work.
I yet ignore many other files that I don't want to commit changing the content of the file .gitignore itself, but it seems that this method doesn't work to ignore pom.xml and .gitignore files.

Any idea about why this happens? Is there a way to solve the problem?

1615903
  • 32,635
  • 12
  • 70
  • 99
user2572526
  • 1,219
  • 2
  • 17
  • 35
  • 3
    Possible duplicate of [git ignore files only locally](http://stackoverflow.com/questions/1753070/git-ignore-files-only-locally) – Rumid Mar 31 '17 at 09:01
  • 2
    Pick command, which best suits your needs from this thread: http://stackoverflow.com/questions/13630849/git-difference-between-assume-unchanged-and-skip-worktree – Rumid Mar 31 '17 at 09:03
  • What would you like to ignore changes you are making to your pom file? – khmarbaise Mar 31 '17 at 10:20
  • 1
    .pom files and .gitignore files are not forcibly "unignored" in git. If you already have a rule in .gitignore set up for them but they are showing up as modified (which is what you want to avid from happening and that's why you set up the rule on .gitignore in the first place, right?) then it is probably because .gitignore is only considered for _new_files. If a file has already been committed (in other words, it's part of HEAD) and you add a rule to start ignoring them on .gitignore, it won't work. – eftshift0 Mar 31 '17 at 14:18
  • If that's the case (a file is already committed and you want to start "ignoring it" if it changes on your working tree) you have to use git update-index for that purpose. – eftshift0 Mar 31 '17 at 14:18

1 Answers1

4

If the gitignore and pom files have already been checked in, then subsequently adding them to gitignore will not cause them to be ignored. You can remove the from the index (cache) with git rm --cached .gitignore however, what I think you really want is

 git update-index --assume-unchanged .gitignore

and similar for pom.xml.

which simply does what it says. If you need to undo that action use --no-assume-unchanged

Andiih
  • 12,285
  • 10
  • 57
  • 88
  • The first step works very well. But you will have to uncheck not only pom.xml but also .gitignore using these commands: 'git rm --cached .gitignore' and 'git rm --cached pom.xml' – AfamO Feb 03 '22 at 08:11