我最近开始使用 Git,但只有一件事遇到了麻烦。如何在不跟踪目录内容的情况下跟踪目录?
例如,我正在开发的网站允许上传。我想跟踪上传目录,以便在分支等时创建它,但显然不是其中的文件(在开发分支中的测试文件或主控中的真实文件)。
在我的 .gitignore 中,我有以下内容:
uploads/*.*
也尝试过(忽略整个目录):
uploads/
该目录还可能包含子目录(uploads/thumbs/ uploads/videos/),我希望能够跟踪这些子目录,但不能跟踪它们的文件。
这可以用 Git 实现吗?我到处寻找但没有找到答案。
Git 不跟踪目录,而是跟踪文件,因此要实现这一目标,您需要跟踪至少一个文件。所以假设你的.gitignore
文件看起来像这样:
upload/*
你可以这样做:
$ touch upload/.placeholder
$ git add -f upload/.placeholder
如果您忘记了-f
你会看到的:
$ git add upload/.placeholder
The following paths are ignored by one of your .gitignore files:
upload
Use -f if you really want to add them.
fatal: no files added
然后当你这样做时git status
你会看到的:
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached ..." to unstage)
#
# new file: upload/.placeholder
#
显然你可以这样做:
$ touch upload/images/.placeholder
$ git add -f upload/images/.placeholder
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)