简体   繁体   English

忽略git commit的某些更改

[英]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: 我们团队的成员使用不同版本的visual studio,VS似乎使用以下代码自动更新sln文件:

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual C# Express 2010

or 要么

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? 我们可以配置git来忽略这些变化吗? We're not interested in this line, but we are interested in other changes of the .sln file, eg adding of new csproj to the solution. 我们对这一行不感兴趣,但我们对.sln文件的其他更改感兴趣,例如在解决方案中添加新的csproj。

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. 一个简单的解决方案是创建.sln文件的两个版本,并告诉团队打开与其版本对应的版本。

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索引以忽略某些文件中的更改,如下所示:

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. 另一种解决方案是将文件添加到.gitignore如果您不想将其保留在源代码管理下。

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 .<whatever>proj , like .csproj , .vbproj etc) XML files and uses them to build a project. 我只是忽略.sln文件,因为它们与构建项目无关:微软很久以前意识到项目文件必须是可版本化的,并且所有由Studio完成的构建都是由msbuild引擎执行的,它.proj那些.proj (和其他.<whatever>proj ,如.csproj.vbproj等)XML文件并使用它们来构建项目。 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. 您可以向git添加一个涂抹/清除过滤器,它会调用一个脚本来调整特定行,以便在提交时保持一致。 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. 在“ Can git自动在空格和制表符之间切换? ”中,它显示了如何实现类似的更改,其中空格在结帐时转换为制表符,并在提交时返回到空格。

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. 您可能需要编写脚本来识别和修改相关行,而链接的示例使用预先存在的unix命令在选项卡和空格之间进行交换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM