Git:反向忽略(.gitignore) [英] Git: inverse ignoring (.gitignore)

查看:1794
本文介绍了Git:反向忽略(.gitignore)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的主文件夹创建了一个存储库。这是我的 .gitignore 文件:

  !. vim / plugin / * 
!.vim / doc / *
。*
*
.viminfo
.vim / .netrwhist
.vim-fuf-data / file / stats
bin / dwm / dwm

所以当我在 .vim / plugin 我预计在 git status 之后会显示此文件,但不会为什么?



编辑:在一对答案后,我改变了反向忽略行的位置,但问题是一样的:我在 .vim / plugin 文件夹不会显示在 git status 之后。

 。* 
*
.viminfo
.vim / .netrwhist
.vim-fuf-data / file / stats
bin / dwm / dwm
!.vim / plugin / *
!.vim / doc / *


解决方案

在第4行中,您忽略了所有使用 * 的所有内容。这覆盖了以前的否定模式。从手册页


在一个优先级内,最后一个匹配模式决定
结果

其中优先级别表示忽略模式的不同来源,如 .gitignore $ GIT_DIR / info / exclude $ b

如果你想忽略一切,但以开始的模式,你应该移动 * .gitignore
$ b




编辑

我在另一个问题

*
!* /
!.vim / plugin / *


I created a repository for my home folder. This is my .gitignore file:

!.vim/plugin/*
!.vim/doc/*
.*
*
.viminfo
.vim/.netrwhist
.vim-fuf-data/file/stats
bin/dwm/dwm

So when I create a new file inside .vim/plugin I expected that after git status this file was shown, but no..why?

EDIT: after a pair of answers I changed the position of inverse ignoring lines this way below, but the problems is the same: the new files I create inside the .vim/plugin folder are not shown after git status..

.*
*
.viminfo
.vim/.netrwhist
.vim-fuf-data/file/stats
bin/dwm/dwm
!.vim/plugin/*
!.vim/doc/*

解决方案

In line 4 you're ignoring everything with *. This overrides the previous negating pattern. From the man page:

within one level of precedence, the last matching pattern decides the outcome

Where "level of precedence" means different sources for ignore patterns like .gitignore and $GIT_DIR/info/exclude.

If you want to ignore everything but the patterns beginning with ! you should move the * to the beginning of .gitignore


Edit

I found a solution with the help of another question on SO:

*
!*/
!.vim/plugin/*

这篇关于Git:反向忽略(.gitignore)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆