i use git to manage my sources,i have some file in bellow paths:
Debug/a.dll
Debug/b.exe
Debug/c.png
Debug/Pic/a.png
Debug/Pic/b.bmp
Debug/Pic/c.dll
<
Git use the .gitignore
to ignore or to track files in ignored paths.
In your case you need to do add this to your .gitignore
file in your project root directory. Create the file is it does not exist
#List of files to ignore
Debug/*
#List of files to exclude from the ignored pattern above
!Debug/Pic
!Debug/Pic/*
.gitignore
Debug/*
- This will ignore all the files under the Debug folder
!Debug/Pic/*
- The !
is a special character in this case telling git to exclude the given pattern from the ignored paths.
In other words:
We "told" git to ignore all the files under the Debug
folder but to include all the files under the Debug/Pic/
folder.
As usual, with exclusion in gitignore
, the rule to remember is:
It is not possible to re-include a file if a parent directory of that file is excluded (*)
(*
: unless certain conditions are met in git 2.?, see below)
Since Debug/*
would ignore the folder Debug/Pic/
, trying to exclude the content of that folder would not work (!Debug/Pic/*
) with git 2.6 or less.
You need to exclude the folder first. Then its content.
Debug/*
!Debug/Pic/
!Debug/Pic/*
Note that with git 2.9.x/2.10 (mid 2016?), it might be possible to re-include a file if a parent directory of that file is excluded if there is no wildcard in the path re-included.
Nguyễn Thái Ngọc Duy (pclouds) is trying to add this feature:
So in git 2.9+, in order to re-include the the folder Debug/Pic/
, you can do:
/Debug
!Debug/Pic
You can add the subdirectory first, then ignore the containing directory:
git add Debug/Pic
git ignore Debug
This will have the side effect of not showing the addition of new files to Debug/Pic, but you can just add them manually with 'git add -f' to get around the .gitignore warning.