• Git—.gitignore忽略文件


    转载自:Eran等博客

    https://www.cnblogs.com/eran/p/afb3d3ad799ffb8c38978bd4045f2b22.html

    https://blog.csdn.net/afanyusong/article/details/60581200

    模板链接:

    https://github.com/github/gitignore

    模板例子:

    ## Ignore Visual Studio temporary files, build results, and    
    ## files generated by popular Visual Studio add-ons.    
        
    # User-specific files    
    *.suo    
    *.user    
    *.userosscache    
    *.sln.docstates    
        
    # User-specific files (MonoDevelop/Xamarin Studio)    
    *.userprefs    
        
    # Build results    
    [Dd]ebug/    
    [Dd]ebugPublic/    
    [Rr]elease/    
    [Rr]eleases/    
    x64/    
    x86/    
    bld/    
    [Bb]in/    
    [Oo]bj/    
    [Ll]og/    
        
    # Visual Studio 2015 cache/options directory    
    .vs/    
    # Uncomment if you have tasks that create the project's static files in wwwroot    
    #wwwroot/    
        
    # MSTest test Results    
    [Tt]est[Rr]esult*/    
    [Bb]uild[Ll]og.*    
        
    # NUNIT    
    *.VisualState.xml    
    TestResult.xml    
        
    # Build Results of an ATL Project    
    [Dd]ebugPS/    
    [Rr]eleasePS/    
    dlldata.c    
        
    # DNX    
    project.lock.json    
    artifacts/    
        
    *_i.c    
    *_p.c    
    *_i.h    
    *.ilk    
    *.meta    
    *.obj    
    *.pch    
    *.pdb    
    *.pgc    
    *.pgd    
    *.rsp    
    *.sbr    
    *.tlb    
    *.tli    
    *.tlh    
    *.tmp    
    *.tmp_proj    
    *.log    
    *.vspscc    
    *.vssscc    
    .builds    
    *.pidb    
    *.svclog    
    *.scc    
        
    # Chutzpah Test files    
    _Chutzpah*    
        
    # Visual C++ cache files    
    ipch/    
    *.aps    
    *.ncb    
    *.opendb    
    *.opensdf    
    *.sdf    
    *.cachefile    
        
    # Visual Studio profiler    
    *.psess    
    *.vsp    
    *.vspx    
    *.sap    
        
    # TFS 2012 Local Workspace    
    $tf/    
        
    # Guidance Automation Toolkit    
    *.gpState    
        
    # ReSharper is a .NET coding add-in    
    _ReSharper*/    
    *.[Rr]e[Ss]harper    
    *.DotSettings.user    
        
    # JustCode is a .NET coding add-in    
    .JustCode    
        
    # TeamCity is a build add-in    
    _TeamCity*    
        
    # DotCover is a Code Coverage Tool    
    *.dotCover    
        
    # NCrunch    
    _NCrunch_*    
    .*crunch*.local.xml    
    nCrunchTemp_*    
        
    # MightyMoose    
    *.mm.*    
    AutoTest.Net/    
        
    # Web workbench (sass)    
    .sass-cache/    
        
    # Installshield output folder    
    [Ee]xpress/    
        
    # DocProject is a documentation generator add-in    
    DocProject/buildhelp/    
    DocProject/Help/*.HxT    
    DocProject/Help/*.HxC    
    DocProject/Help/*.hhc    
    DocProject/Help/*.hhk    
    DocProject/Help/*.hhp    
    DocProject/Help/Html2    
    DocProject/Help/html    
        
    # Click-Once directory    
    publish/    
        
    # Publish Web Output    
    *.[Pp]ublish.xml    
    *.azurePubxml    
    # TODO: Comment the next line if you want to checkin your web deploy settings     
    # but database connection strings (with potential passwords) will be unencrypted    
    *.pubxml    
    *.publishproj    
        
    # NuGet Packages    
    *.nupkg    
    # The packages folder can be ignored because of Package Restore    
    **/packages/*    
    # except build/, which is used as an MSBuild target.    
    !**/packages/build/    
    # Uncomment if necessary however generally it will be regenerated when needed    
    #!**/packages/repositories.config    
    # NuGet v3's project.json files produces more ignoreable files    
    *.nuget.props    
    *.nuget.targets    
        
    # Microsoft Azure Build Output    
    csx/    
    *.build.csdef    
        
    # Microsoft Azure Emulator    
    ecf/    
    rcf/    
        
    # Windows Store app package directories and files    
    AppPackages/    
    BundleArtifacts/    
    Package.StoreAssociation.xml    
    _pkginfo.txt    
        
    # Visual Studio cache files    
    # files ending in .cache can be ignored    
    *.[Cc]ache    
    # but keep track of directories ending in .cache    
    !*.[Cc]ache/    
        
    # Others    
    ClientBin/    
    ~$*    
    *~    
    *.dbmdl    
    *.dbproj.schemaview    
    *.pfx    
    *.publishsettings    
    node_modules/    
    orleans.codegen.cs    
        
    # Since there are multiple workflows, uncomment next line to ignore bower_components     
    # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)    
    #bower_components/    
        
    # RIA/Silverlight projects    
    Generated_Code/    
        
    # Backup & report files from converting an old project file    
    # to a newer Visual Studio version. Backup files are not needed,    
    # because we have git ;-)    
    _UpgradeReport_Files/    
    Backup*/    
    UpgradeLog*.XML    
    UpgradeLog*.htm    
        
    # SQL Server files    
    *.mdf    
    *.ldf    
        
    # Business Intelligence projects    
    *.rdl.data    
    *.bim.layout    
    *.bim_*.settings    
        
    # Microsoft Fakes    
    FakesAssemblies/    
        
    # GhostDoc plugin setting file    
    *.GhostDoc.xml    
        
    # Node.js Tools for Visual Studio    
    .ntvs_analysis.dat    
        
    # Visual Studio 6 build log    
    *.plg    
        
    # Visual Studio 6 workspace options file    
    *.opt    
        
    # Visual Studio LightSwitch build output    
    **/*.HTMLClient/GeneratedArtifacts    
    **/*.DesktopClient/GeneratedArtifacts    
    **/*.DesktopClient/ModelManifest.xml    
    **/*.Server/GeneratedArtifacts    
    **/*.Server/ModelManifest.xml    
    _Pvt_Extensions    
        
    # Paket dependency manager    
    .paket/paket.exe    
    paket-files/    
        
    # FAKE - F# Make    
    .fake/    
        
    # JetBrains Rider    
    .idea/    
    *.sln.iml    
    View Code
    /[Ll]ibrary/
    /[Tt]emp/
    /[Oo]bj/
    /[Bb]uild/
    [Bb]uilds/
    /Assets/AssetStoreTools*
    
    # Autogenerated VS/MD/Consulo solution and project files
    ExportedObj/
    .consulo/
    *.csproj
    *.unityproj
    *.sln
    *.suo
    *.tmp
    *.user
    *.userprefs
    *.pidb
    
    *.booproj
    *.svd
    
    
    # Unity3D generated meta files
    *.pidb.meta
    
    # Unity3D Generated File On Crash Reports
    sysinfo.txt
    
    # Builds
    *.apk
    *.unitypackage
    View Code

    Git 中忽略某些文件或者文件夹

    项目中经常会生成一些Git系统不需要追踪(track)的文件。典型的是在编译生成过程中 产生的文件或是编程器生成的临时备份文件。

    版本控制系统(VCS:Version Control System)会记录文件的所有改动,同时还提供将某些文件排除在版本控制之外。

    git设置忽略列表

    git的忽略列表信息在每个目录的.gitignore文件中,该文件记录该目录及子目录中需要排除在版本控制之外的文件及文件夹列表。

    1)、在项目初始化时,.gitignore文件已经在项目中;

             1. 在需要创建  .gitignore 文件的文件夹, 右键选择

                 Git Bash 进入命令行,进入项目所在目录。

             2. 输入 touch .gitignore 在文件夹就生成了一个“.gitignore”文件。/注意空位符

                 然后在”.gitignore” 文件里输入你要忽略的文件夹及其文件就可以了。。。。。(不知道自己建一个文本行不行,没试过)

    git的本地忽略设置 必须保证git的远程仓库分支上没有这个要忽略的文件 ,如果远程分支上存在这个文件,本地在设置ignore

    这个文件,将会失败,无法commit忽略。

    也就是说,假如你要忽略某些文件,在.gitignore生效前就不要提交它,也就是说在初始化、第一次提交项目时就最好确定好.gitignore文件,否则比如:.idea中文件,每个人每台电脑上都不一样,假如你第一次提交了,虽然后来你在.gitignore里忽略了,但是还是一直会提示你本地文件改变但是尚未提交”。

    2)、忽略文件原则

    1. 忽略操作系统自动生成的文件,比如缩略图等;
    2. 忽略编译生成的中间文件、可执行文件等,也就是如果一个文件是通过另一个文件自动生成的,那自动生成的文件就没必要放进版本库,比如Java编译产生的.class文件;
    3. 忽略你自己的带有敏感信息的配置文件,比如存放口令的配置文件。

    3)、语法规范

    • 空行或是以#开头的行即注释行将被忽略;
    • 以斜杠 “/” 结尾表示目录;
    • 以星号 “*” 通配多个字符;
    • 以问号 “?” 通配单个字符
    • 以方括号 “[]” 包含单个字符的匹配列表;
    • 以叹号 “!” 表示不忽略(跟踪)匹配到的文件或目录;
    • 可以在前面添加斜杠 “/” 来避免递归,下面的例子中可以很明白的看出来与下一条的区别。
    • 注意:git不支持空目录的版本控制,所以如果要上传一个空目录,请在该目录中添加一个空的.gitignore文件。

      更多的语法请看http://git-scm.com/docs/gitignore
    忽略 .a 文件
    *.a
    
    # 但否定忽略 lib.a, 尽管已经在前面忽略了 .a 文件
    !lib.a
    
    # 仅在当前目录下忽略 TODO 文件, 但不包括子目录下的 subdir/TODO
    /TODO
    
    # 忽略 build/ 文件夹下的所有文件
    build/
    
    # 忽略 doc/notes.txt, 不包括 doc/server/arch.txt
    doc/*.txt
    
    # 忽略所有的 .pdf 文件 在 doc/ directory 下的
    doc/**/*.pdf
    经测试发现,若要忽略一个文件夹下的部分文件夹,应该一个一个的标示。可能有更好的方法。
    若test下有多个文件和文件夹。若要ignore某些文件夹,应该这个配置.gitignore文件。若test下有test1,test2,test3文件。要track test3,则.gitignore文件为:
    test/test1
    test/test2
    !test/test3
    若为:
    test/
    !test/test3 ,则不能track test3。
    Git 中的文件忽略
    1. 共享式忽略新建 .gitignore 文件,放在工程目录任意位置即可。.gitignore 文件可以忽略自己。忽略的文件,只针对未跟踪文件有效,对已加入版本库的文件无效。
    2. 独享式忽略针对具体版本库 :.git/info/exclude针对本地全局:  git config --global core.excludefile ~/.gitignore
    忽略的语法规则:
    (#)表示注释
    (*)  表示任意多个字符; 
    (?) 代表一个字符;
     ([abc]) 代表可选字符范围
    如果名称最前面是路径分隔符 (/) ,表示忽略的该文件在此目录下。
    如果名称的最后面是 (/) ,表示忽略整个目录,但同名文件不忽略。
    通过在名称前面加 (!) ,代表不忽略。
    例子如下:
    # 这行是注释
    *.a                   # 忽略所有 .a 伟扩展名的文件
    !lib.a                # 但是 lib.a 不忽略,即时之前设置了忽略所有的 .a
    /TODO            # 只忽略此目录下 TODO 文件,子目录的 TODO 不忽略 
    build/               # 忽略所有的 build/ 目录下文件
    doc/*.txt           # 忽略如 doc/notes.txt, 但是不忽略如 doc/server/arch.txt

    4)、.gitignore分为全局配置和局部配置

    这个很容易理解全局配置是指修改当前.gitignore文件本机的git中的全部项目都起作用,局部的配置是指每个项目下的.gitignore文件只对向前所在的项目起作用。

    局部的配置只需要在项目目录中创建 .gitignore 文件即可。

    全局的配置设置方法为:

    $git config –global core.excludesfile ~/.gitignore

    这样,修改 ~/.gitignore 这个文件将作用于所有 git 项目,并且作用于项目实例中的所有被跟踪的目录。

    5)、注意&问题事项

      1.在 Edit->Project Settings->Editor->Version Control Mode 中选择 Visible Meta files。

      2.在 Edit->Project Settings->Editor->Asset Serialization Mode 中选择 Force Text。
     
     
    这两个是要设置的.
     
    主要问题是在.gitignore的模板里面.  请参照github的模板对自己项目进行调整.
     
    注意的是 *.meta 是不能忽略的, 忽略的是 *.pidb.meta
     
    这个就是我之前无论如何同步 两边总是报Missing Prefab的原因.
     
     
    svn设置忽略列表

    svn不是用具体的文件来保存忽略列表,而是是用目录属性的方式标记忽略列表(当然属性还包括其他内容)。设置方法有两种:

    1. 设置目录属性: 在文件夹或空白处右击->【TortoiseSVN】->【Properties...】, 在新界面中选择【New】->【Other】, 设置Property name("svn:ignore"),Property value(namelist)。 namelist每行一个名字,支持通配符'*',格式跟git的一样。 注意:右击文件夹表示设置的属性为该目录,右击空白处表示设置的属性为当前目录!

    2. 快速添加忽略列表: 在选中要忽略的文件及文件夹处右击->【TortoiseSVN】->【Unversion add to ignore list】->【Delete and ignore n items by name】。
    余生很长,愿我们都活成自己喜欢的样子
  • 相关阅读:
    [CF833B] The Bakery
    [CF1203F1] Complete the Projects
    [CF354C] Vasya and Beautiful Arrays
    [CF7D] Palindrome Degree
    [CF1466F] Euclid's nightmare
    【转】node-webkit:开发桌面+WEB混合型应用的神器
    (转)background-position—CSS设置背景图片的位置
    (转)国外漂亮表格连接地址
    URL转义
    T-SQL实用查询之常用SQL语句
  • 原文地址:https://www.cnblogs.com/bananana/p/8819752.html
Copyright © 2020-2023  润新知