Git pull ignore image files

I am the author of a repository that sometimes has images posted on it. Images are not really significant, but other participants will continue to add and push them to the repository. I would like to perform pull operations that ignore the suffixes of image files, for example *.png . The git directory just takes up too much space, and I really don't need to pull these image files.

How can I not pull image files, but get everything else?

+6
source share
1 answer

You can use sparse-checkout to cut your working directory. sparse-checkout uses the skip-worktree , which allows git to assume that the file in the working tree is updated no matter what.


In the following cases, I assume that you are currently in the root directory of your repository and have a clean working tree ( git stash for example.).

First you need to enable sparse-checkout with git config core.sparsecheckout true ; after that you can define all the templates that you want to β€œignore” when placing an order in .git/info/sparse-checkout .
The syntax is the same as in the .gitignore file, the difference is that you define all the files that you want to check , not the ones you want to ignore.

Suppose you want to avoid checking all png files in your repository, then your sparse-checkout file might look like this:

 * # Include everything !*.png # Flag png files with the 'skip-worktree' bit 

If you want to apply sparse-checkout to the current working directory, you must run the read-tree command.

 git read-tree -m -u HEAD 

After that, you can continue to work with your repository, as usual, without the "ignored" files in the working tree.


TL DR:

  • Activate sparse-checkout : git config core.sparsecheckout true
  • Define the sparse-checkout file in .git/info/ containing the file templates you want to include
  • Update working tree git read-tree -m -u HEAD

More information about sparse-checkout can be found in the official git read-tree documentation.

+5
source

Source: https://habr.com/ru/post/979440/


All Articles