Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
502 views
in Technique[技术] by (71.8m points)

windows xp - git ignore exception not working as desired

WinXP + mysisGit1.7

In my .gitignore file, but still can't see Demos/path/to/file/file.cpp being tracked by git.

I have below entries:

Demos/
!Demos/path/to/file/file.cpp

The absolute path is: c:ProjectDemospathofilefile.cpp

What could be wrong? Please help, thanks.


EDIT:

I found the way how mysisGit .gitignore work on WindowsXP can only ignore certain type of file, then exclude some files with same type. For example:

*.bak
!tracking.bak
!/path/to/file/tracking2.bak

It doesn't work ignore folder and exclude some files under that folder. Below won't work:

/folderUnderRepoRoot/
!/folderUnderRepoRoot/tracking.cpp

Nor

anyFolderNamedLikeThis/
!anyFolderNamedLikeThis/tracking.cpp
!/anyFolderNamedLikeThis/tracking.cpp

However, I do find that there's an exception. There's a work-around way to exclude files just right under the ignored folder (not to its subfolder). This works.

/folderUnderRepoRoot/*
/folderUnderRepoRoot/tracking.cpp

But this way is only limited when the file is not in any subfolder, so it's not so useful.

So I end up still commit most of source files, even I was only interested in a few files while tracking some others big project. Which means there're a bunch of files I won't touch but still need to commit them.

Here is another thread that had similar problem.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your .gitignore exception does not work because "It is not possible to re-include a file if a parent directory of that file is excluded" (source). This is "a performance related quirk in Git" (source).

As an ugly-but-functional workaround, do this for every directory in the path to your file:

  1. Exclude the contents of the directory.
  2. Re-include the sub-directory leading to your file (resp. finally, re-include your file).

Your entries would look like this, with each two-line section corresponding to the two steps above for one directory level:

Demos/*
!Demos/path/

Demos/path/*
!Demos/path/to/

Demos/path/to/*
!Demos/path/to/file/

Demos/path/to/file/*
!Demos/path/to/file/file.cpp

Notes:

The first line is not Demos/, unlike what the question author tried. Demos is a parent directory of our file, so we would have to re-include it right afterwards – means, we do not have to exclude it in the first place. Instead, we start by excluding only its contents: Demos/*.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...