我只想在一个更大的项目中跟踪git中的某些目录,其中大多数目录将被排除,只有少数目录将被跟踪.所以,我想在我的.gitignore中使用not-operators或者排除文件,ja?
为什么会这样:
% 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)
Run Code Online (Sandbox Code Playgroud)
"not"语法适用于最高目录中的文件.
% 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
#
Run Code Online (Sandbox Code Playgroud)
我怎么能得到这个给我baz和foo作为git跟踪文件?(基本上,目录NOT-style globbing是如何工作的?!似乎没有.)
谢谢!
小智 18
恢复旧帖子,万一其他人偶然发现:
如果要忽略当前目录中的所有文件夹/文件,请使用前导斜杠(/*/对于目录或/*文件); 否则Git将以递归方式忽略该模式,这将导致未签名目录中的文件也被忽略...
考虑到这一点,该!directory/模式使目录完全正确.
Tri*_*onX 15
要强制添加被忽略的文件夹,请使用:
git add -f my-ignored-folder
Run Code Online (Sandbox Code Playgroud)
不要提及 .gitignore 中的目录,只提及文件。执行此操作并显式添加您想要跟踪的目录应该会给您带来您想要的结果:
$ 猫 > .gitignore << EOF * !酒吧 EOF $ git add -f 我想要这些文件
这将使 git 跟踪 bar 和 iwanthesefiles 目录中的所有内容。