本文介绍了.git递归除.c和.h以外的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了 .c .h 文件之外,我想忽略某个文件夹及其子文件夹中的所有内容.

I would like to ignore everything in a certain folder and its subfolders, except for .c and .h files.

但是在本地,我也需要其他文件.在添加 .gitignore 之前或之后,我是否必须在git-repo中拥有这些不应跟踪的文件?

Yet locally, i need other files too. Do i have to have these files, which should not be tracked, in the git-repo before or after i add the .gitignore?

我该怎么做?:

#ignore all
*
#but:
!source/**/*.c
!source/**/*.h

这是我当前的解决方案,但是它不起作用.但是我认为这也与时间点有关,在该时间点我必须添加文件,应该忽略这些文件,但是需要在本地存放这些文件?

This is my current solution, but it does not work. But i think this also relates to the point in time, where i have to add the files, that should be ignored, but need to be there locally?

问题是,我得到了一个项目的副本,该副本可以执行各种makefile魔术等操作,我什至不知道存在哪种文件类型和子文件夹(我只能在大型项目的一个文件夹中工作,所以我不认为gitignore必须如此排他)...而且我不能只提交所有内容,因为我认为必须安装"lib",因此每个人都需要自己完成此操作...

The problem is, i got a copy of a project, that does all kinds of makefile magic and other things, i do not even know what kind of file-types and subfolders there are (i will only work in one folder of the massive project, so i don't think, that the gitignore needs to be so exclusive) ... and i can't just commit everything, because the "lib" has to be installed i think, so everybody needs to do this on his own ...

推荐答案

忽略 * 意味着忽略所有内容,包括顶级目录.之后, git 甚至不会查看子目录.要修复该目录.您的整个 .gitignore 应该如下所示:

Ignoring * means ignore everything including top-level directories. After that git doesn't even look into subdirectories. To fix that unignore directories. Your entire .gitignore should look like this:

# Ignore all
*

# Unignore directories
!*/

# Unignore source code files
!source/**/*.c
!source/**/*.h

另一种方法是忽略所有内容,但使用 git add -f .

Another approach is to ignore everything but force-add necessary files with git add -f.

这篇关于.git递归除.c和.h以外的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 14:03