我想忽略目录中除一个文件之外的所有文件。
我在我的 git bash 中执行以下操作。
$ mkdir dir_to_ignore
$ cd dir_to_ignore
$ vi file_to_ignore.txt
# (I put some content and save the file)
$ vi second_file.txt
# (Some text and then save the file. I dont wish this file to be ignored)
$ cd ..
$ vi .gitignore
我将以下内容放入.gitignore
文件中:
dir_to_ignore/
!dir_to_ignore/second_file.txt
但现在当我执行 git status
时,我没有将 second_file.txt
视为未跟踪文件。
为什么会这样?
最佳答案
忽略目录似乎有点奇怪,但尝试在忽略的目录中跟踪文件,因为要跟踪文件,您可能需要知道文件的完整路径,包括它所在的目录。
如果您将 .gitignore
文件更改为此:
dir_to_ignore/*
!second_file.txt
这将忽略 dir_to_ignore
下的所有文件,second_file.txt
除外。您仍然需要跟踪该目录,以便同时跟踪 second_file.txt
。
关于git - 使用否定前缀忽略目录中除 GIT 中的文件之外的所有文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16745781/