Ignore certain changes for git commit
Members of our team uses different version of visual studio, and VS seems to automatically update the sln file with code like:
Microsoft Visual Studio Solution File, Format Version 11.00 # Visual C# Express 2010
Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2012
whenever we work with the solution. Can we configure git to ignore such changes? We’re not interested in this line, but we are interested in other changes of the .sln file, e.g. adding of new csproj to the solution.
4 Solutions collect form web for “Ignore certain changes for git commit”
It’s not possible to partially ignore a file. A simple solution would be to create two versions of the .sln file, and tell the team to open the one corresponding to their version.
Another solution would be a post-commit hook that rejects the commit if these lines are changed. Needs a bit of scripting, but it’s feasible.
On your local side you can simply update git index to ignore changes in certain file like this:
git update-index --assume-unchanged SolutionFile.sln
The same thing can do any of your developers.
Another solution would be adding the file to
.gitignore if you don’t want to keep it under source control.
I would just ignore the
.sln files for they are not relevant to building a project: Microsoft realized some time ago that project files must be versionable and novadays all building done by the Studio is carried out by
msbuild engine which takes those
.proj (and other
.vbproj etc) XML files and uses them to build a project. Those files is actually everything which is needed to build a project, and the solution file just contains various bookkeeping information.
You can add a smudge/clean filter to git which calls a script to tweak the particular line to be consistent when committing. In “Can git automatically switch between spaces and tabs?”, it shows how to implement a similar change, where spaces are converted to tabs on checkout, and back to spaces on commit.
You’ll probably need to write the script to identify and modify the relevant line, whereas the linked example uses pre-existing unix commands for swapping between tabs and spaces.