Git拉忽略图像文件 [英] Git pull ignore image files
问题描述
我是存储库中的贡献者,偶尔会发布映像。图片真的不是必需的,但其他贡献者将继续添加
和 push
到存储库。我想执行忽略图像文件后缀的 pull
操作,比如 *。png
。 git目录只占用太多空间,我真的不需要拉这些图像文件。
我怎么能不拉
图像文件,但获取其他所有内容其他?
sparse-checkout
来稀疏地填充你的工作目录。 sparse-checkout
利用 skip-worktree
,这让git认为工作树中的文件是最新的。无论如何。 b
对于以下内容,我假设您目前在您的存储库的根目录并且有一个干净的工作树(首先你必须启用
稀疏结帐$ c $>例如)
git config core.sparsecheckout true
;在此之后,您可以在 .git / info / sparse-checkout
结帐时定义您想要忽略的所有模式。语法相同就像
.gitignore
文件一样,不同之处在于您定义了要结账的所有文件,而不是您想要忽略的文件。 假设您想避免检出存储库中的所有 png
文件,那么您的 sparse- checkout
文件可能如下所示:
*#包含所有
!*。png #用'skip-worktree'位标记png文件
如果你想应用 sparse-checkout
到你当前的工作目录,你必须执行 read-tree
命令。
git read-tree -m -u HEAD
之后你可以继续像往常一样使用您的存储库,而没有工作树中的忽略文件。
$ b
TL; DR :
- 激活
稀疏结帐
:git config core.sparsecheckout true
- 在
稀疏检出
文件> .git / info / 包含您想要的文件模式 include - 更新您的工作树
git read-tree -m -u HEAD
您可以在 sparse-checkout 的更多信息/git-read-tree.html#_sparse_checkoutrel =nofollow> git read-tree
。
I'm a contributor on a repository that occasionally has images posted to it. The images are really not essential, but the other contributors will continue to add
and push
them to the repository. I would like to perform pull
operations that ignore image file suffixes, such as *.png
. The git directory is just taking up too much space, and I really don't need to be pulling these image files.
How can I not pull
the image files, but get everything else?
You can use sparse-checkout
to sparsly populate your working directory. sparse-checkout
makes use of the skip-worktree
bit which makes git assume that the file in your working tree is up to date no matter what.
For the following I'll assume that you are currently in the root of your repository and have a clean working tree (git stash
e.g.).
First you have to enable sparse-checkout
using git config core.sparsecheckout true
; after this you can define all patterns you want to "ignore" on checkout in .git/info/sparse-checkout
.
The syntax is the same as in a .gitignore
file, the difference being that you define all files you want to checkout not the ones you want to ignore.
Let's assume you want to avoid checking out all png
files in your repository, then your sparse-checkout
file could look like this:
* # Include everything
!*.png # Flag png files with the 'skip-worktree' bit
If you want to apply the sparse-checkout
to your current working directory you have to execute a read-tree
command afterwards.
git read-tree -m -u HEAD
After that you can continue working with your repository as usual, without the "ignored" files in your working tree.
TL;DR:
- Activate
sparse-checkout
:git config core.sparsecheckout true
- Define a
sparse-checkout
file under.git/info/
containing the patterns of files you want to include - Update your working tree
git read-tree -m -u HEAD
You can read more on sparse-checkout
in the official documentation of git read-tree
.
这篇关于Git拉忽略图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!