如何添加git ignore规则忽略的文件

时间:2015-07-19 15:38:41

标签: git symlink gitignore

在我的.gitignore中,我有:

*.framework
*.a

但是,我在各种项目中使用符号链接,因为符号链接在.a.framework中,我似乎无法将这些符号链接到Git中。

是否有一个我失踪的命令或一轮工作?我想检查符号链接,以便我不必每次都创建它们。如果需要,我总是可以编写一个bash脚本来制作这些脚本。

1 个答案:

答案 0 :(得分:3)

Git只使用路径来确定它是否应该忽略文件 - 因此,如果可以派生出一种模式,只捕获您不想要的文件并排除所有文件我想要 - 这是最佳选择。

但是,请记住,git忽略规则不是一成不变的;它总是可以添加文件,你只需要使用--force标志:

$ cat .gitignore 
*.a
$ git status --ignored
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   .gitignore
# Ignored files:
#   (use "git add -f <file>..." to include in what will be committed)
#
#   bar.a
#   foo.a
nothing added to commit but untracked files present (use "git add" to track)
$ git add foo.a
The following paths are ignored by one of your .gitignore files:
foo.a
Use -f if you really want to add them.
fatal: no files added
$

在这种情况下似乎经常被遗漏的是帮助输出中的这一行:

  

如果你真的想添加它们,请使用-f。

使用force选项,添加被忽略的文件:

$ git add -f foo.a
$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#   new file:   foo.a
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   .gitignore
$  git status --ignored
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#   new file:   foo.a
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   .gitignore
# Ignored files:
#   (use "git add -f <file>..." to include in what will be committed)
#
#   bar.a
$