How do I track only specific files using .gitignor

2019-04-14 05:08发布

This question already has an answer here:

What should I put in my Git repository's .gitignore to exclude all files and directories there except specific ones. For example if I have a large number of files and directories in a repo, and just want Git to track fileX, .fileY, and directoryZ, but completely ignore everything else, what should be in my .gitignore?

标签: git gitignore
1条回答
ら.Afraid
2楼-- · 2019-04-14 05:38

You should ignore content; but exclude folders.
That allows you to exclude files.

/**
!/**/
!fileX

That is because:

It is not possible to re-include a file if a parent directory of that file is excluded.

Check the effect of a .gitignore with git checkignore -v

git check-ignore -v -- afile
查看更多
登录 后发表回答