0

So I am trying to ignore a file called my_settings.py in git. If I make any changes, git actually ignores them and doesn't tell me to commit them. But every time I change the branch, the file either gets overwritten or git won't let me change the branch, because your changes would be overwritten by checkout. I'm working in a developer team and am the only one left with this issue. The file is not part of .gitignore, because one should be able to pull it, then make changes to it that don't get commited. This works for everyone in my team but me and I don't get it. A colleague pulled the repo again and the problem was gone for him. He didn't even need to use any commands such as git update-index. I tried that and it didn't work. I tried git update-index --assume-unchanged, I tried git update-index --skip-worktree, I tried adding the file to info/exclude. Nothing works. I really have no idea how to fix this.

  • 1
    easy and fast solution is to delete the local repo and clone it again – shahaf May 14 '18 at 10:47
  • 3
    if it is not part of gitignore, how should git know everytime not to take its changes as potential commits? and why should pulling not overwrite it? I would take the file out of the repo, add it to gitignore and the problem should be fixed. Then you also wouldn't have to manually add only needed changes to commits but could just add all. Once a new member comes to the team, just give them the file – ghoulfolk May 14 '18 at 10:53
  • @shahaf did that three times today. changed nothing. @ghoulfolk `update-index --assume-unchanged` is supposed to take care of that. – Manu Brodach May 14 '18 at 11:19
  • As I said, I don't want to touch .gitignore. And we don't want to take the file out of the repo and always hand it over manually. I just noticed, that the problem only exists in one particular branch. I don't get it. – Manu Brodach May 14 '18 at 11:28
  • Well if you don't wish to use gitignore to solve the issue, all I can advise is to remove it from assume-unchanged and then put it back, see if it fixes it. in this thread (https://stackoverflow.com/questions/17195861/undo-git-update-index-assume-unchanged-file) there are more things you can try, like checking all assume-unchanged and alternative solutions to debug the ultimate cause. BTW I used to have a similar project with files only pulled once. We solved it by creating a completely different repo for those files which were then only pulled once. That's another alternative. – ghoulfolk May 14 '18 at 11:40
  • I added it to .gitignore now. It's not an ideal solution, but it'll have to do for now. But I still have the problem that when I change the branch, the file still gets overwritten. – Manu Brodach May 14 '18 at 14:37
  • This is the weirdest problem with git that I have faced so far. It makes me nuts. – Manu Brodach May 14 '18 at 15:58

2 Answers2

0

Run below commands if you have added new files in .gitignore to be ignored:

  • git rm -r --cached . it will remove all the staged changes, so be sure that you have committed your changes
  • git add .
  • git commit -m "ignore files"
beingmanish
  • 1,040
  • 8
  • 21
0

There is no way to do exactly what you are trying to do – either a file is tracked by git or it is not, you can't half-track a file.

Usually the solution for files like this, where you want a single copy of the file to be in the repo but any changes you make to be ignored, is to have a differently-named file in the repo that each developer renames when they clone the repository.

For example if you had a config file called config.json that contains secret API keys, you could commit a copy without the API keys called config.json.example, then when each developer clones the repository, they copy it to config.json and insert their API keys.

ash
  • 5,139
  • 2
  • 27
  • 39