Git不会忽略目录 [英] Git Won't Un-Ignore a Directory

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

问题描述

我想只在一个较大的项目中跟踪git中的某些目录,其中大多数目录将被排除,只有少数目录会被跟踪。所以,我想在我的.gitignore或排除文件中使用非运算符,ja?



为什么会发生这种情况:

 %mkdir wtfgit 
%cd wtfgit
%git init
在/home/foobar/wtfgit/.git/中初始化空的Git存储库
%mkdir iwantthesefiles
%touch iwantthesefiles / foo
%mkdir idontwantthesefiles
%touch idontwantthesefiles / bar
%vim .gitignore
%cat .gitignore
*
!iwantthesefiles /
%git add --all
git status
#分支主

#初始提交$ b $

没有提交(创建/复制文件并使用git add p>not语法适用于最高级目录中的文件。

 %touch baz 
%vim。 gitignore
%cat .gitignore
*
!iwantthesefiles /
!baz
%git add --all
git status
#On分支大师

#初始提交

#对b的更改e提交:
#(使用git rm --cached< file> ...来取消)

#新文件:baz

我如何得到这个给我baz和foo作为git跟踪文件? (基本上,NOT-style globbing目录是怎样工作的?!它似乎不是。)

谢谢!

/ * / 用于目录或 / * 用于文件);否则Git会递归地忽略模式,这会导致无匹配目录中的文件也被忽略......



考虑到这一点,!目录/ 模式unignores目录就好了。


I'd like to only track certain directories in git in a larger project, where most directories will be excluded and only a few will be tracked. So, I wanted to use the not-operators in my .gitignore or excludes file, ja?

Why is this happening:

% mkdir wtfgit
% cd wtfgit 
% git init
Initialized empty Git repository in /home/foobar/wtfgit/.git/
% mkdir iwantthesefiles
% touch iwantthesefiles/foo
% mkdir idontwantthesefiles
% touch idontwantthesefiles/bar
% vim .gitignore
% cat .gitignore 
*
!iwantthesefiles/        
% git add --all
% git status
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)

The "not" syntax works fine for files in the highest directory.

% touch baz          
% vim .gitignore
% cat .gitignore 
*
!iwantthesefiles/
!baz
% git add --all 
% git status    
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#   new file:   baz
#

How can I get this to give me baz and foo as git tracked files? (Basically, how does the directory NOT-style globbing work at all?! It seems not to.)

Thanks!

解决方案

Reviving an old post, in case someone else stumbles on this:

If you want to ignore all folders/files in the current directory, use a leading slash (/*/ for directories or /* for files); else Git will ignore the pattern recursively, which will cause files in unignored directories to be ignored too...

With that in mind, the !directory/ pattern unignores directories just fine.

这篇关于Git不会忽略目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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