GIT checkout except one folder

杀马特。学长 韩版系。学妹 提交于 2019-12-02 20:54:51

You could use sparse checkout to exclude the committed contents of the node_modules directory from the working tree. As the documentation says:

"Sparse checkout" allows populating the working directory sparsely. It uses the skip-worktree bit to tell Git whether a file in the working directory is worth looking at.

Here's how you use it. First, you enable the sparseCheckout option:

git config core.sparseCheckout true

Then, you add the node_modules path as a negation in the .git/info/sparse-checkout file:

echo -e "/*\n!node_modules" >> .git/info/sparse-checkout

This will create a file called sparse-checkout containing:

/*
!node_modules

which effectively means ignore the node_modules directory when reading a commit's tree into the working directory.

If you later want to include the node_modules directory again (i.e. remove the skip-worktree bit from its files) you have to modify the sparse-checkout file to only contain /* – that is "include all paths" – and update your working directory using git read-tree:

echo "/*" > .git/info/sparse-checkout
git read-tree -mu HEAD

You can then disable sparse checkout altogether by setting its configuration variable to false:

git config core.sparseCheckout false

Note that sparse checkout was first introduced in Git 1.7.0.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!