I have a large project that I'm working on as part of a team of 10 developers, and there are several configuration files and other settings-related files that need to be different for every one of us.
I know the obvious solution to this is to not source control those files at all, either by adding them to .gitignore
files or by adding them to <project root dir>/.git/info/exclude
.
The problems with those approaches are:
- The files are already in source control, which means
.git/info/exclude
won't work. - My teammates refuse to introduce
.gitignore
files, for various reasons that I won't bore you with.
So after some research I came across the git update-index
command and its --assume-unchanged
option, which seemed perfect for my use case. I now have the troublesome files marked with that, and also have a post-checkout
hook that copies my own local copies of the files from an external directory, into the correct places every time I checkout.
This mostly works, and has the following benefits:
- My settings are always correct for my local dev environment.
- The Git changes window in Visual Studio remains clear of those files, meaning that I can't accidentally forget to not stage them before a commit (I'm used to always staging and committing everything in one fell swoop).
The only problem is that sometimes, for some strange reason completely beyond my understanding, git seems to "forget" that I have explicitly told it to ignore those files, resulting in the following:
- Make some changes to files that I eventually want to commit.
- The boss comes along and says "this critical bug has just popped up, drop everything and fix it immediately!" so I
git stash
,git checkout master
and attempt togit pull
1. - Git tells me
error: Your local changes to the following files would be overwritten by merge: <list of files>
. - After swearing at and bashing the keyboard for 5 minutes, I realise that I need to
git update-index --no-assume-unchanged <list of files>
, thengit checkout -- <list of files>
, thengit pull
, then finallygit checkout -b new-bugfix-branch
1.
So why does this happen, and is there a better way to achieve the results mentioned above? MTIA :-)
1: Running these commands is not how I actually do things; as hinted at before I use the Git Changes window to do almost-everything Git-related, and only resort to full terminal commands when absolutely necessary. But the actions that I would take in said UI are equivalent to the commands given.