Git: How to ignore/specify files for *checkout*

前端 未结 5 1168
日久生厌
日久生厌 2021-02-13 02:56

If I don\'t want .html files tracked I can add the pattern to .gitignore and they\'ll be ignored. I\'d like to know how I can do the converse - at checkout, how could I ask git

5条回答
  •  花落未央
    2021-02-13 03:31

    Git's Sparse-Checkout

    If you only want to checkout a portion of your repository, you can use git's sparse-checkout option which has powerful include/exclude rules.

    The following StackOverflow question has some helpful instructions:
    GIT checkout except one folder

    But as a summary:

    1. Enable the sparseCheckout option:

      git config core.sparseCheckout true
      
    2. Create the file called .git/info/sparse-checkout containing:

      /*
      !node_modules
      

      which effectively means include everything except the node_modules directory when checking out a repository into the working directory.

提交回复
热议问题