会用.gitignore么?

这两天用.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/ directory
build/
# ignore doc/notes.txt, but not doc/server/arch.txt
doc/*.txt
# ignore all .txt files in the doc/ directory
doc/**/*.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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值