Gitignore:添加排除文件夹中的文件

时间:2014-01-09 16:46:15

标签: git

目前,我.gitignore中有以下内容:

...
sites/default/files/*
!sites/default/files/Library/bannerpt2.jpg
...

我想要完成的是sites/default/files/sites/default/files/Library/bannerpt2.jpg之外我不想要任何{{1}}

2 个答案:

答案 0 :(得分:4)

不幸的是,您需要手动包含路径中的所有子目录。这应该有效:

...
sites/default/files/*
!sites/default/files/Library/

sites/default/files/Library/*
!sites/default/files/Library/bannerpt2.jpg
...

答案 1 :(得分:3)

您可以使用git add -f file

在排除的文件夹中添加文件

样本互动:

$ git init
Initialized empty Git repository in /Users/killerx/temp/.git/
$ echo "*" > .gitignore
$ touch a.txt
$ git add a.txt
The following paths are ignored by one of your .gitignore files:
a.txt
Use -f if you really want to add them.
fatal: no files added
$ git add -f a.txt
$ git commit -m "t"
[master (root-commit) db22f19] t
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a.txt
$ echo "a" > a.txt
$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   a.txt
#
no changes added to commit (use "git add" and/or "git commit -a")