Domanda

In my repo I have the following directory structure:

/
|-dir1
|    |-file1
|    |-file2
|    |-file3
|-dir2
|    |-file4
|    |-file5.derp
|    |-file6
|-dir3
     |-file7
     |-file8

My .gitignore file (located at the root) is as follows:

dir2/
!dir2/*.derp

However, file5.derp is never found by git add...

What am I missing here?

È stato utile?

Soluzione

Try a .gitignore like this:

dir2/*
!dir2/*.derp

Per gitignore man page: http://www.kernel.org/pub/software/scm/git/docs/gitignore.html

If the pattern ends with a slash, it is removed for the purpose of the following description, but it would only find a match with a directory. In other words, foo/ will match a directory foo and paths underneath it, but will not match a regular file or a symbolic link foo (this is consistent with the way how pathspec works in general in git).

I suspect it's ignoring all files in that directory and not getting to the point where it would check using !.

Altri suggerimenti

You will have to have it like:

dir2/*
!dir2/*.derp

In what you tried, dir2/, obviously, ignores the directory, and git will not descend into it to unignore the .derp files. In the above case, it ignore all children of dir2 and not dir2 itself because of dir2/* and then you unignore the .derp files

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top