使用 .gitignore来忽略某些文件

具体使用请看 man gitignore

 

一般某个项目dev过程中都会产生一些中间文件,这些文件是我们不想要追踪的。

git中可以使用.gitignore文件来忽略这些文件。

 

在需要的目录下面 添加 .gitignore文件

文件中每一行表示需要忽略的文件的正则表达式。

$cat .gitignore
#ignore .metadata
.metadata
.gitignore

#ignore obj and lib file

*.[oa]

 

当前的目录情况

$ls -al
total 24
drwxr-xr-x  4 root root 4096 2010-12-11 12:44 .
drwx------ 51 root root 4096 2010-12-11 12:44 ..
drwxr-xr-x  8 root root 4096 2010-12-11 12:44 .git
-rw-r--r--  1 root root   39 2010-12-11 12:44 .gitignore
drwxr-xr-x  3 root root 4096 2010-08-19 20:01 .metadata
-rw-r--r--  1 root root   52 2010-12-11 12:41 test.txt

 

如果没有添加该文件,git status会报有这些文件没有track。

$git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#    .metadata/
#    gitignore

 

而 添加了该文件后,就可以看到,这个workspace 就是干净的了。

$mv gitignore .gitignore
[root@~/workspace]
$git status
# On branch master
nothing to commit (working directory clean)

 

这个.gitignore很简单,当前目录下有个.metadata,这个是我们不需要的,所以就写入了文件。另外如果不加.gitignore这行,git会把.gitignore也加入版本控制中。

 

 

 

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值