gitignore

.gitignore的用法

在日常的开发中,当我们需要将一个项目提交到Git时,并不是所有的文件都需要提交,比如一些自动生成的文件,这时候就可以使用.gitignore来忽略一些不需要提交的文件,本文着重介绍一下.gitignore的配置语法。

  • 1、配置语法:

以斜杠“/”开头表示目录;

以星号“*”通配多个字符;

以问号“?”通配单个字符

以方括号“[]”包含单个字符的匹配列表;

以叹号“!”表示不忽略(跟踪)匹配到的文件或目录;

此外,git 对于 .ignore 配置文件是按行从上到下进行规则匹配的,意味着如果前面的规则匹配的范围更大,则后面的规则将不会生效;

  • 2、 忽略文件的原则是:

  • 忽略操作系统自动生成的文件,比如缩略图等;

  • 忽略编译生成的中间文件、可执行文件等,也就是如果一个文件是通过另一个文件自动生成的,那自动生成的文件就没必要放进版本库,比如Java编译产生的.class文件;

  • 忽略你自己的带有敏感信息的配置文件,比如存放口令的配置文件。

  • 3、示例:

(1)规则:fd1/*
     说明:忽略目录 fd1 下的全部内容;注意,不管是根目录下的 /fd1/ 目录,还是某个子目录 /child/fd1/ 目录,都会被忽略;

(2)规则:/fd1/*
     说明:忽略根目录下的 /fd1/ 目录的全部内容;

(3)规则:

/*
!.gitignore
!/fw/bin/
!/fw/sf/

说明:忽略全部内容,但是不忽略 .gitignore 文件、根目录下的 /fw/bin/ 和 /fw/sf/ 目录;

  • Xcode下简便配置.gitignore文件,配置内容可复制一下内容:
# Xcode
.DS_Store
*/build/*
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
profile
*.moved-aside
DerivedData
.idea/
*.hmap
*.xccheckout
*.xcworkspace
!default.xcworkspace

#CocoaPods
Pods
!Podfile
!Podfile.lock

有列子如下:


➜  Desktop  cd yueba
➜  yueba git:(master) ✗ cd yueba
➜  yueba git:(master) ✗ git st
On branch master
Your branch is up-to-date with 'origin/master'.
  1 # Xcode
  2 #
  3 # gitignore contributors: remember to update Global/Xcode.gitignore, Objecti    ve-C.gitignore & Swift.gitignore
  4 
  5 ## Build generated
  6 build/     忽略build下的所有文件
  7 DerivedData/   同上
  8 
  9 ## Various settings
 10 *.pbxuser    忽略所有以   .pbxuser 结尾的文件
 11 !default.pbxuser   不忽略 default.pbxuser这个文件
 12 *.mode1v3 
 13 !default.mode1v3   12/13行同10/11行
 14 *.mode2v3
 15 !default.mode2v3
 16 *.perspectivev3
 17 !default.perspectivev3
 18 xcuserdata/
 19 
 20 ## Other
 21 *.moved-aside
 22 *.xcuserstate
 23 */project.xcworkspace/*   忽略路径中带有 project.xcworkspace  的所有文件夹下的文件

-- INSERT --                                                  1,1           Top

以下是github中.gitignore针对objective-c的内容,原链接 https://github.com/github/gitignore

# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/

## Other
*.moved-aside
*.xcuserstate

## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output

# Code Injection
#
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 对于经常使用Git的朋友来说,.gitignore配置一定不会陌生。废话不说多了,接下来就来说说这个.gitign...
    Sherry凤阅读 3,644评论 0 0
  • .gitignore 忽略特殊文件 有些时候,你必须把某些文件放到Git工作目录中,但又不能提交它们,比如保存了数...
    Crazy2015阅读 10,794评论 0 1
  • 海棠社(70) 要求:要以“风雪夜归人”入诗 主题:五律 文/寒霜 【原创】 盼归 庭院青灯颤,衾寒枕冷襟。 双瞳...
    刘寒霜阅读 2,755评论 18 19
  • 抖落冰雪衣,细雨润花浓。谁解东风意?梅香贯长虹!
    飘渺孤鸿_阅读 1,468评论 1 2
  • 黄堡文化研究 第211期作者:张晓辉编辑:秦陇华 周末,在穆家庄的小山村里,历经了一场民间古老的习俗,那就是浇木...
    primates阅读 4,353评论 0 1

友情链接更多精彩内容