在我的.gitignore
文件中,我有:
*.framework
*.a
然而,我在多个项目中使用符号链接,并且由于符号链接位于 .a
或者 .framework
中,我似乎无法将它们检入Git。
我是否遗漏了某个命令或者有什么变通方法? 我想检查这些符号链接以便不必每次都创建它们。 如果需要,我可以编写一个Bash脚本来制作这些符号链接。
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
$
使用 force 选项可以添加被忽略的文件:如果你真的想添加它们,请使用 -f 选项。
$ 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
$
.framework
被视为目录,因此这可能只需要使用行*.framework/
(注意尾随/
)即可解决。如前所述,您可能需要rm --cached
之前提交的框架。 - brichins