使 GIT 忽略 DLL、PDB 和类似的生成文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31543997/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 11:13:16  来源:igfitidea点击:

Make GIT ignore DLL,PDB and similar generate files

gitvisual-studio

提问by Mauricio Gracia Gutierrez

I have issues convicing GIT to ingore generated files

我在说服 GIT 输入生成的文件时遇到问题

Here is an example of the files that I want to ignore

这是我想忽略的文件的示例

    modified:   BLLTarifario/bin/Debug/BLLTarifario.dll
    modified:   BLLTarifario/bin/Debug/BLLTarifario.pdb
    modified:   BLLTarifario/bin/Debug/Corte.Library.dll
    modified:   BLLTarifario/bin/Debug/Corte.Library.pdb
    modified:   BLLTarifario/obj/Debug/BLLTarifario.csprojResolveAssemblyReference.cache
    modified:   BLLTarifario/obj/Debug/BLLTarifario.dll
    modified:   BLLTarifario/obj/Debug/BLLTarifario.pdb
    modified:   Corte.Library/bin/Debug/Corte.Library.dll
    modified:   Corte.Library/bin/Debug/Corte.Library.pdb
    modified:   Corte.Library/obj/Debug/Corte.Library.csprojResolveAssemblyReference.cache
    modified:   Corte.Library/obj/Debug/Corte.Library.dll
    modified:   Corte.Library/obj/Debug/Corte.Library.pdb
    modified:   Tarifario.Site/bin/BLLTarifario.dll
    modified:   Tarifario.Site/bin/BLLTarifario.pdb
    modified:   Tarifario.Site/bin/Corte.Library.dll
    modified:   Tarifario.Site/bin/Corte.Library.pdb
    modified:   Tarifario.Site/bin/Tarifario.Site.dll
    modified:   Tarifario.Site/bin/Tarifario.Site.pdb
    modified:   Tarifario.Site/obj/Debug/Tarifario.Site.csprojResolveAssemblyReference.cache
    modified:   Tarifario.Site/obj/Debug/Tarifario.Site.dll
    modified:   Tarifario.Site/obj/Debug/Tarifario.Site.pdb
    modified:   TestValidate/bin/Debug/BLLTarifario.dll
    modified:   TestValidate/bin/Debug/BLLTarifario.pdb
    modified:   TestValidate/bin/Debug/Corte.Library.dll
    modified:   TestValidate/bin/Debug/Corte.Library.pdb
    modified:   TestValidate/bin/Debug/TestValidate.exe
    modified:   TestValidate/bin/Debug/TestValidate.pdb
    modified:   TestValidate/obj/x86/Debug/TestValidate.csprojResolveAssemblyReference.cache
    modified:   TestValidate/obj/x86/Debug/TestValidate.exe
    modified:   TestValidate/obj/x86/Debug/TestValidate.pdb

And here is the .gitignore

这是.gitignore

/build/
*.suo
*.user
_ReSharper.*/
*.sdf
bin/
obj/
Debug/
Release/
*.opensdf
*.tlog
*.log
TestResult.xml
*.VisualState.xml
Version.cs
Version.h
Version.cpp
*/bin/*
*/obj/*

回答by Will Eddins

It looks like you had these files already committed before you added your rules to the .gitignorefile. Git will continue to monitor files that are already being tracked.

在将规则添加到.gitignore文件之前,您似乎已经提交了这些文件。Git 将继续监视已经被跟踪的文件。

You'll need to make a commit where you remove these files, then they should be ignored afterwards.

您需要在删除这些文件的地方进行提交,然后它们应该被忽略。

Edit:To remove a folder and it's contents recursively, use git rm -r, for example:

编辑:要递归删除文件夹及其内容,请使用git rm -r,例如:

git rm -r "./BLLTarifario/bin/"

You'll need to do this for each of the binand objdirectories that you want to delete.

您需要为要删除的每个binobj目录执行此操作。

Optionally, you can delete the folders (since they'll be rebuilt at compile time) and run git add -Aagain to stage the deleted changes. See: Staging Deleted files

或者,您可以删除文件夹(因为它们将在编译时重建)并git add -A再次运行以暂存已删除的更改。请参阅:暂存已删除的文件

Since I only needed to remove them from the REPO I run this command for every single file

因为我只需要从 REPO 中删除它们,所以我对每个文件都运行这个命令

git rm --cached BLLTarifario/bin/Debug/BLLTarifario.dll

And the final .gitignorefile is this

最后的.gitignore文件是这个

*.cache
*.dll
*.exe
*.pdb
/build/
*.suo
*.user
_ReSharper.*/
*.sdf
*.opensdf
*.tlog
*.log
TestResult.xml
*.VisualState.xml
Version.cs
Version.h
Version.cpp

回答by Bzil

What is the result if you put

如果你把结果是什么

.dll
.pdb
.cache
.exe

into your .gitignorefile .

进入你的.gitignore文件。

回答by insight

It will simply ignore them, the reason why you need to perform git rm -r [/bin]is to remove the files from git tracking, simply adding them to your .gitignore file after tracking won't stop git from pushing subsequent changes to your git repository

它会简单地忽略它们,您需要执行的原因git rm -r [/bin]是从 git 跟踪中删除文件,在跟踪后简单地将它们添加到您的 .gitignore 文件不会阻止 git 将后续更改推送到您的 git 存储库