3

We have a couple people working on a single Atmel Studio 7 project that is in a git repo. Everytime someone opens the project, Atmel Studio makes some user-specific changes to the project file (*.cproj) like adding the serial number of the debug probe and updating the exact Atmel Studio version number it was opened with. I'd like to ignore these changes, but still keep the file in the repo since it includes all of the necessary project settings.

Does anyone have a good solution to this problem?

rkor
  • 63
  • 7
  • If the `.cproj` file is already in the repo, why can't you just add it to `.gitignore`? – SHG Jun 06 '19 at 21:01
  • `git update-index --assume-unchanged `. Each user will have to run this command in their own sandbox. – joanis Jun 07 '19 at 02:18
  • This question is almost certainly a duplicate, but my search is not revealing a question that's just what you want. – joanis Jun 07 '19 at 02:20
  • OK, so I still can't find a good post on this, even though I'm sure I learned this solution on SO, so I'm posting my solution as an answer. – joanis Jun 07 '19 at 13:14

1 Answers1

2

You can use git update-index to accomplish what you want.

In each user's sandbox, run this command:

git update-index --assume-unchanged <file>

This will tell Git to ignore all changes to <file> in this sandbox from now on.

Should you ever change your mind and want to commit changes to <file>, you will have to reverse that action first, because git add and other commands just won't see any changes to a file marked assume-unchanged:

git update-index --no-assume-unchanged <file>

EDIT, two years later...

A better solution is to use:

git update-undex --skip-worktree <file>

It's meant exactly for the use case here.

joanis
  • 10,635
  • 14
  • 30
  • 40
  • Thank you, this will work! Is the only difference between doing this and adding the file to the .gitignore just that your new method remains local to my machine? – rkor Jun 07 '19 at 13:51
  • Looks like it also works with wildcards, so I can just run ```git update-index --assume-unchanged *.cproj```! – rkor Jun 07 '19 at 13:53
  • No, the bigger difference is that `.gitignore` will never have any effect on a file that is already tracked. It only filters things out of the Untracked files list, but once a file is tracked Git considers it has to follow changes on it. I believe only the assume-unchanged setting can override that. – joanis Jun 07 '19 at 13:54
  • Ok, that makes sense. So does that mean that the index update will apply for everyone who uses the repo, or just me? – rkor Jun 07 '19 at 13:56
  • Just you, and only in the sandbox where you ran it. That's why each user has to run it, and in each sandbox if you use more than one sandbox. – joanis Jun 07 '19 at 13:57