【Git】.gitignore文件的说明。
来源:互联网 发布:c语言怎么做界面 编辑:程序博客网 时间:2024/05/20 20:56
官方文档:https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository
.gitgnore的作用是用来忽略掉某些文件。粗略翻译下官方文档关于.gitignore 部分(原文在文章最后面)。
.gitgnore是用来忽略掉某些文件的,添加至.gitgnore的文件。将不会被add进Git Respository。
关于.gitignore文件有五条规则。
1、空白行或者以#号开始的行将会被忽略,不会生效
2、支持简单的正则匹配
3、你可以使用/来作为一个pattern作为开始来避免递归调用(?反正我不大懂这意思)
4、你可以使用/作为一个pattern的结束符来表示一个具体的目录(这个也不大懂)
5、你可以使用!来将某个文件从忽略列表中剔除。
具体例子如下:
1、注释某行
# “# 开头的行将会被作为注释不会起到作用,空白行同样不会起作用”
2、忽略所有的java文件
*.java
3、只忽略掉和.gitignore同级的tood文件夹。而不忽略掉res/tood下的tood文件夹
/tood
4、忽略掉tood文件下的所有东西
tood/
5、不忽略hello.java这个文件,即使你开始编写了*.java忽略掉所有java文件的语句,但hello.java这个文件不会被忽略。
!hello.java。
Android项目基本的.gitignore文件的配置
# 忽略bin目录的所有文件/bin# 忽略gen目录的所有文件/gen
忽略部分原文摘录如下:
Ignoring Files
Often, you’ll have a class of files that you don’t want Git to automatically add or even show you as being untracked. These are generally automatically generated files such as log files or files produced by your build system. In such cases, you can create a file listing patterns to match them named .gitignore
. Here is an example.gitignore
file:
$
cat .gitignore*.[oa]
*~
The first line tells Git to ignore any files ending in “.o” or “.a” – object and archive files that may be the product of building your code. The second line tells Git to ignore all files whose names end with a tilde (~
), which is used by many text editors such as Emacs to mark temporary files. You may also include a log, tmp, or pid directory; automatically generated documentation; and so on. Setting up a.gitignore
file before you get going is generally a good idea so you don’t accidentally commit files that you really don’t want in your Git repository.
The rules for the patterns you can put in the .gitignore
file are as follows:
Blank lines or lines starting with
#
are ignored.Standard glob patterns work.
You can start patterns with a forward slash (
/
) to avoid recursivity.You can end patterns with a forward slash (
/
) to specify a directory.You can negate a pattern by starting it with an exclamation point (
!
).
Glob patterns are like simplified regular expressions that shells use. An asterisk (*
) matches zero or more characters;[abc]
matches any character inside the brackets (in this case a, b, or c); a question mark (?
) matches a single character; and brackets enclosing characters separated by a hyphen ([0-9]
) matches any character between them (in this case 0 through 9). You can also use two asterisks to match nested directories;a/**/z
would match a/z
, a/b/z
, a/b/c/z
, and so on.
Here is another example .gitignore file:
# no .a files*.a# but do track lib.a, even though you're ignoring .a files above!lib.a# only ignore the TODO file in the current directory, not subdir/TODO/TODO# ignore all files in the build/ directorybuild/# ignore doc/notes.txt, but not doc/server/arch.txtdoc/*.txt# ignore all .pdf files in the doc/ directorydoc/**/*.pdf
Tip
GitHub maintains a fairly comprehensive list of good .gitignore
file examples for dozens of projects and languages athttps://github.com/github/gitignore if you want a starting point for your project.
- 【Git】.gitignore文件的说明。
- git 的gitignore文件
- git的.gitignore文件
- git的.gitignore文件例子
- git的 .gitignore 文件编写
- Git 的 .gitignore 配置说明 (C#)
- 关于git的.gitignore文件的总结
- git的.gitignore文件的修改规则
- Quick Reference: git 的.gitignore文件
- 为项目添加git的.gitignore文件
- Git的.gitignore文件配置格式。。。
- iOS git .gitignore 文件的常见写法
- git中.gitignore文件的使用方法
- Git忽略文件.gitignore的使用
- Git中.gitignore文件的使用
- Git忽略文件.gitignore的使用
- Git中.gitignore文件不起作用的解决
- Git .gitignore文件比较完善的写法
- 拉马努金恒等式
- 堆、堆排序及Java实现
- QQ在通信与传输的一些知识
- iOS多线程同步
- ubuntu 配置 tftp 服务器
- 【Git】.gitignore文件的说明。
- mybatis的oracle数据库操作
- 一种基于UDP协议实现P2P智能穿越NAT的方案
- Ubuntu 常见问题汇总
- 操作系统调度算法
- 读书笔记---Naive Bayes
- 并查集
- markdown语法
- Android ORM框架介绍之OrmLite注解与封装