问题
I work in an environment where people use two different IDEs (Visual Studio and Xamarin Studio) to work on the same code. Unfortunately, they generate slightly different versions of the file Resource.Designer.cs. This is an auto-generated file but we do need it in VC, or the project will complain when you try to build it after cloning.
The problem here is that we do need this file in vc, BUT the tiny changes are highly annoying. If you commit the project with one IDE, then someone downloads the project into the other and rebuilds, you see a change to that file. Then if you try to switch branches, Git may refuse because of the merge conflict. Similarly, if you try to merge two branches, you are pretty much guaranteed to see a merge conflict in the header of that file.
The same problem occurs if two people build using the same IDE, but slightly different versions of the runtime. I am looking at an example right now with the following change showing in Git:
- // Runtime Version: 4.0.30319.18444
+ // Runtime Version: 4.0.30319.34011
One fix that would solve the problem is, for this file only, to have Git always choose the "local" version of comments, and to ignore all changes to comments. But I don't know if there is a way to do that. If not, is there another way to avoid having constant hassles with small changes to this file?
回答1:
Our dev teams address this by committing the Resource.Designer.cs
to our Git repo. After that, each developer can run git update-index --assume-unchanged Resource.Designer.cs
to make Git ignore updates to that file.
After updating the index, changes made to the Resource.Designer
file will not appear in the "Changes not staged for commit" section when doing a git status
.
If a commit to that file becomes necessary just execute git update-index --no-assume-unchanged Resource.Designer.cs
and Git will start tracking changes to that file again.
回答2:
There are several ways to address this issue in git. See: https://gist.github.com/canton7/1423106. The link deals with config files but you can apply it to your situation as needed.
I think simplest way to solve this is commit the file as Resource.Designer.cs.in
, and then after cloning manually copy it to Resource.Designer.cs
. Also add Resource.Designer.cs
to your .gitignore
file.
来源:https://stackoverflow.com/questions/22619935/resource-designer-cs-under-git