会用.gitignore么?

来源:互联网 发布:iis7 php http503 编辑:程序博客网 时间:2024/06/04 22:26

这两天用.gitignore出了点问题,查阅了相当文档巩固下。

Create a local .gitignore
.gitignore文件可以提交到你的版本库里面,这样其他人pull代码的时候就可以看到你定义的
忽略规则了。当然也可以选择忽略(不提交),只需在.gitignore文件里面添加规则:.gitignore
准备提交代码之前,最好先写好.gitignore文件的忽略规则,万一代码已经tracked,而你又想忽略:

git rm --cached  file1.txt  (file1.txt为你想忽略的文件)
Create a global .gitignore
配置全局的忽略规则,跟你配置git的user、email一样
git config --global core.excludesfile ~/.gitignore_global
这里有些全局的忽略规则:
https://gist.github.com/octocat/9257657
Ignoring versioned files
项目中的某个文件经常变动,但是不想提交到线上的环境里面,如经常更改变动的config文件,
怎么做比较好呢?
git update-index --assume-unchanged path/to/file.txt
这样当你执行git status或git diff时,你在本地对path/to/file.txt做的任何变动,都不会被tracked。
git update-index --no-assume-unchanged path/to/file.txt 
这样就又可以被tracked了
How to edit .gitignore file
$ cat .gitignore*.[oa]*~
*.[oa]:将会忽略任何以 .o或.a为后缀名的文件;*~:将会忽略以~结束的文件或目录
.gitignore编写规则遵循如下四点:
1、空白行或以“#”开头的,将不产生任何作用,以“#”开头的为注释文件;
2、符合标准的glob;
3、忽略指定的目录,目录名后加“/”;
4、针对单个文件或目录,不想忽略,加“!”
(看例子)
# a comment - this is ignored# no .a files*.a# but do track lib.a, even though you're ignoring .a files above!lib.a# only ignore the root TODO file, not subdir/TODO/TODO# ignore all files in the build/ directorybuild/# ignore doc/notes.txt, but not doc/server/arch.txtdoc/*.txt# ignore all .txt files in the doc/ directorydoc/**/*.txt
更复杂点的:可参看 http://git-scm.com/docs/gitignore
这玩意儿,找个文件夹试试就清楚了。

参考链接:

http://git-scm.com/docs/gitignore

http://git-scm.com/book/en/Git-Basics-Recording-Changes-to-the-Repository#Ignoring-Files

https://help.github.com/articles/ignoring-files

0 0
原创粉丝点击