我知道.gitignore文件隐藏Git版本控制中的指定文件。
我如何告诉.gitignore忽略除我使用Git跟踪的文件之外的所有内容?类似于:
# Ignore everything:
*
# Do not ignore these files:
script.pl
template.latex
我知道.gitignore文件隐藏Git版本控制中的指定文件。
我如何告诉.gitignore忽略除我使用Git跟踪的文件之外的所有内容?类似于:
# Ignore everything:
*
# Do not ignore these files:
script.pl
template.latex
当前回答
如果您需要忽略除少数文件和少数根文件夹之外的所有内容,则简单的解决方案:
/*
!.gitignore
!showMe.txt
!my_visible_dir
神奇的是在/*(如上所述)中,它忽略(根)文件夹中的所有内容,但不递归。
其他回答
可选前缀!这否定了该模式;排除的任何匹配文件将再次包括先前的模式。如果否定模式匹配,这将覆盖优先级较低的模式源。
# Ignore everything
*
# But not these files...
!.gitignore
!script.pl
!template.latex
# etc...
# ...even if they are in subdirectories
!*/
# if the files to be tracked are in subdirectories
!*/a/b/file1.txt
!*/a/b/c/*
如果您需要忽略除少数文件和少数根文件夹之外的所有内容,则简单的解决方案:
/*
!.gitignore
!showMe.txt
!my_visible_dir
神奇的是在/*(如上所述)中,它忽略(根)文件夹中的所有内容,但不递归。
这就是我保持文件夹结构的方式,而忽略其他所有内容。每个目录(或.gitkeep)中都必须有一个README.md文件。
/data/*
!/data/README.md
!/data/input/
/data/input/*
!/data/input/README.md
!/data/output/
/data/output/*
!/data/output/README.md
您可以使用git-config-status.showUntrackedFiles no,所有未跟踪的文件都将对您隐藏。有关详细信息,请参阅man git config。
这里有很多复杂的答案。。。这里有一些我在上面看不到的非常简单的东西,在许多场景中都很有效:
# ignore all files that have an extension
**/*.*
# except for these extensions
!**/*.extension1
!**/*.extension2
这不会忽略任何无扩展名的文件,但是如果您有一堆文件都具有相同或相似的名称,则可以为这些文件添加排除项
**/EXTENSIONLESSFILETOIGNORE