gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 14:05:58 25 4
gpt4 key购买 nike

在我的 .gitignore 中,我有:

*.framework
*.a

但是,我在各种项目中使用符号链接(symbolic link),并且由于符号链接(symbolic link)和 .a.framework,我似乎无法将它们 checkin Git .

是否有我遗漏的命令或变通办法?我想 checkin 符号链接(symbolic link),这样我就不必每次都创建它们。如果需要,我总是可以编写一个 bash 脚本来制作这些。

最佳答案

Git 只使用路径来确定它是否应该忽略文件 - 所以如果有可能派生出一种模式,只捕获你不想要的文件并排除所有你想要的文件 - 就是这样去。

但是,请记住 git ignore 规则并不是一成不变的; 总是可以添加文件,您只需要使用--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
$

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

Use -f if you really want to add them.

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

$ 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
$

关于git - 如何添加被 git ignore 规则忽略的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31502908/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com