1

I'm using git as my version control tool. I have a local.properties file in my remote repository. Every team member has to have this file but git should ignore this file only in terms of changes - not existence. I tried adding this file to .gitignore file (the one in the root directory), but it seems like git is ignoring this request... since I (or any other team member) can still commit and push changes on this file.

What am I missing?

Thanks

Noam
  • 3,049
  • 10
  • 34
  • 52
  • can you share the content of the gitignore file? p.s. sorry for the downvote notification, that was an accidental click, upvoted to balance it! – dubes May 30 '16 at 08:15
  • It's a standard .gitignore file that was created using the .ignore plugin in IntelliJ (it's a big long so I would rather not include it here...) and in the end of the file there is this line: /tests/src/test/resources/application.properties - This file is located in the root folder (project root) – Noam May 30 '16 at 08:42
  • One possible solution is to `git reset HEAD -- local.properties` in the hook `pre-commit`. Once the hook is deployed, local.properties will never be committed even it's added. – ElpieKay May 30 '16 at 08:46
  • Does this answer your question? [How to make Git "forget" about a file that was tracked but is now in .gitignore?](https://stackoverflow.com/questions/1274057/how-to-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore) – jewishmoses Sep 04 '20 at 13:47

1 Answers1

4

You are missing that git ignore mechanism only works for untracked files and you can also always force a file to be added with -f even if it is ignored. You cannot ignore changes to an untracked file. You might read about --ignore-untracked, but this should never be used unless you are a Git expert. Rename your checked in file to local.properties.sample and make your developers copy and adapt it to local.properties which then is in .gitignore.

Vampire
  • 35,631
  • 4
  • 76
  • 102
  • Thanks for the clarification - I did miss that! But the thing is I don't want that the rest of the developers to manually create this file, is that possible? – Noam May 30 '16 at 08:48
  • 1
    As I said, you cannot make Git ignore changes to a tracked file in a safe way. If you want the file ignored, you need to untrack it (delete it from the repo). You could add in your using of the file that it looks for `local.properties` and if it does not exist copy `local.properties.sample` to `local.properties` automatically. This way the individual developer does not have to copy the file manually if he does not need changes to it. – Vampire May 30 '16 at 09:16