我想创建一个我的bash设置和插件以及诸如此类的git repo.我忽略了所有内容(第0行),然后在repo中手动添加了我想要的文件/文件夹.(我必须这样做,因为repo在我的~文件夹中.)我想忽略.vim/colors /目录中的所有颜色配置文件,但我确实想要包含我正在使用的一个文件(apprentice.vim) ).
该.vim/colors/*行似乎不起作用 - 它根本不会忽略任何文件.使用!!.vim/colors/*也不起作用.我怎么能让它覆盖所有以前的规则并忽略colors文件夹,然后仍然允许apprentice.vim文件被忽略?
/*
*.swp
!.gitignore
!.bashrc
!.bash_profile
!.vimrc
!.vim
.vim/colors/* # Don't include all of the other color schemes
!.vim/colors/apprentice.vim
Run Code Online (Sandbox Code Playgroud)
问题与# comment此相同.vim/colors/*,但这里有另一种选择.
gitignore的主要规则是:
这意味着:(
假设元素尚未版本化,在这种情况下,您git rm --cached首先需要它们):
**'**/'结果:
/**
!/**/
!exclude what you want to *not* be ignored
# for instance
.vim/colors/* # Don't include all of the other color schemes
!.vim/colors/apprentice.vim
Run Code Online (Sandbox Code Playgroud)
检查什么是和不被忽略git check-ignore -v(-v重要的是):
git check-ignore -v -- afile
Run Code Online (Sandbox Code Playgroud)
它比手动取消忽略子文件夹更容易,特别是当要忽略的子文件夹内容是多级深度时:要排除文件a/b/c,你需要先忽略!/a,然后!/a/b,然后!/a/b/c)
插图/测试:
C:\Users\vonc\prog\git\tests>git init i
Initialized empty Git repository in C:/Users/vonc/prog/git/tests/i/.git/
C:\Users\vonc\prog\git\tests>cd i
C:\Users\vonc\prog\git\tests\i>mkdir .vim\colors
C:\Users\vonc\prog\git\tests\i>touch .vim\colors\apprentice.vim
C:\Users\vonc\prog\git\tests\i>git st
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
.vim/
nothing added to commit but untracked files present (use "git add" to track)
Run Code Online (Sandbox Code Playgroud)
简单.gitignore的/*规则:
C:\Users\vonc\prog\git\tests\i>sbt .gitignore
/*
C:\Users\vonc\prog\git\tests\i>git st
On branch master
Initial commit
nothing to commit (create/copy files and use "git add" to track)
Run Code Online (Sandbox Code Playgroud)
让我们补充一下!.gitignore.
.gitignore现在可以跟踪.
C:\Users\vonc\prog\git\tests\i>git st
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
nothing added to commit but untracked files present (use "git add" to track)
Run Code Online (Sandbox Code Playgroud)
但如果我补充:
.vim/colors/*
!.vim/colors/apprentice.vim
Run Code Online (Sandbox Code Playgroud)
.vim 所有内容仍然被忽略:
C:\Users\vonc\prog\git\tests\i>git st
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
nothing added to commit but untracked files present (use "git add" to track)
Run Code Online (Sandbox Code Playgroud)
我们来看看为什么git check-ignore:
C:\Users\vonc\prog\git\tests\i>git check-ignore -v -- .vim\colors\apprentice.vim
.gitignore:1:/* ".vim\\colors\\apprentice.vim"
Run Code Online (Sandbox Code Playgroud)
添加!.vim作品,因为它取消忽略该文件夹,允许该文件夹中的其他规则应用.
不过,这更简单:
/**
!/**/
!.gitignore
.vim/colors/*
!.vim/colors/apprentice.vim
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1457 次 |
| 最近记录: |