GIT: 忽略除子目录和一些文件之外的所有内容
GIT: ignore everything except sub-subdirectory and some files
我正在用这个头撞墙,我希望你们能帮助我...
我有这样的文件结构:
/public/images/foo
/public/images/foo/default.jpg
/public/images/foo/1/...
/public/images/foo/2/...
/public/images/bar
/public/images/bar/default.jpg
/public/images/bar/1/...
/public/images/bar/2/...
/public/images/baz
/public/images/baz/default.jpg
/public/images/baz/1/...
/public/images/baz/2/...
/public/images/other/...
我想忽略 images
中的所有内容,但保留 default.jpg
文件和 other
文件夹及其内容。我的 .gitignore 中的内容没有按预期工作,default.jpg
文件仍然被忽略:
/public/images/*
!/public/images/*/default.jpg
!/public/images/other/
感谢您的帮助!
!public/images/**/default.jpg
应该有 2 颗星而不是 1 颗星来表示当前目录。
如果您的文件已经在存储库中,您将必须删除它们,然后才能 "ignore" 它们。
如何删除跟踪文件?
git rm --cached <file>
现在您可以使用 .gitignore
文件了。
如果你想忽略特定文件(在你的情况下你想要文件夹本身所以它适合你的 csse)你可以使用 assume-unchanged
标志
https://git-scm.com/docs/git-update-index
--[无-]assume-unchanged
When this flag is specified, the object names recorded for the paths are not updated.
Instead, this option sets/unsets the "assume unchanged" bit for the paths.
When the "assume unchanged" bit is on, the user promises not to change the file and allows Git to assume that the working tree file matches what is recorded in the index. If you want to change the working tree file, you need to unset the bit to tell Git. This is sometimes helpful when working with a big project on a filesystem that has very slow lstat(2) system call (e.g. cifs).
Git will fail (gracefully) in case it needs to modify this file in the index e.g. when merging in a commit; thus, in case the assumed-untracked file is changed upstream, you will need to handle the situation manually.
好的,我和朋友一起找到了解决方案:
/public/images/*
!/public/images/*/
/public/images/*/*
!/public/images/other/*
!/public/images/*/default.jpg
这里我可以忘记里面的所有东西 images
但是通过命名保留一些文件夹并保留第一级 default.jpg
files.The 问题是你在处理子目录时需要具体白名单。
我正在用这个头撞墙,我希望你们能帮助我... 我有这样的文件结构:
/public/images/foo
/public/images/foo/default.jpg
/public/images/foo/1/...
/public/images/foo/2/...
/public/images/bar
/public/images/bar/default.jpg
/public/images/bar/1/...
/public/images/bar/2/...
/public/images/baz
/public/images/baz/default.jpg
/public/images/baz/1/...
/public/images/baz/2/...
/public/images/other/...
我想忽略 images
中的所有内容,但保留 default.jpg
文件和 other
文件夹及其内容。我的 .gitignore 中的内容没有按预期工作,default.jpg
文件仍然被忽略:
/public/images/*
!/public/images/*/default.jpg
!/public/images/other/
感谢您的帮助!
!public/images/**/default.jpg
应该有 2 颗星而不是 1 颗星来表示当前目录。
如果您的文件已经在存储库中,您将必须删除它们,然后才能 "ignore" 它们。
如何删除跟踪文件?
git rm --cached <file>
现在您可以使用 .gitignore
文件了。
如果你想忽略特定文件(在你的情况下你想要文件夹本身所以它适合你的 csse)你可以使用 assume-unchanged
标志
https://git-scm.com/docs/git-update-index
--[无-]assume-unchanged
When this flag is specified, the object names recorded for the paths are not updated.
Instead, this option sets/unsets the "assume unchanged" bit for the paths.When the "assume unchanged" bit is on, the user promises not to change the file and allows Git to assume that the working tree file matches what is recorded in the index. If you want to change the working tree file, you need to unset the bit to tell Git. This is sometimes helpful when working with a big project on a filesystem that has very slow lstat(2) system call (e.g. cifs).
Git will fail (gracefully) in case it needs to modify this file in the index e.g. when merging in a commit; thus, in case the assumed-untracked file is changed upstream, you will need to handle the situation manually.
好的,我和朋友一起找到了解决方案:
/public/images/*
!/public/images/*/
/public/images/*/*
!/public/images/other/*
!/public/images/*/default.jpg
这里我可以忘记里面的所有东西 images
但是通过命名保留一些文件夹并保留第一级 default.jpg
files.The 问题是你在处理子目录时需要具体白名单。