How do I delete files locally without commiting these deletions to a remote repository while keeping a “clean” working tree?

前端 未结 2 1444
被撕碎了的回忆
被撕碎了的回忆 2021-01-07 09:41

This question is essentially the opposite of this one.

There are certain files that exist for reasons on the team\'s remote. They are not frequently changed

2条回答
  •  灰色年华
    2021-01-07 10:09

    The sparse-checkout should work.

    Enable sparse-checkout:

    git config core.sparsecheckout true
    

    Create the config file .git/info/sparse-checkout and input the patterns:

    *
    !path/to/file1/you/want/to/delete
    !path/to/file2/you/want/to/delete
    !path/to/file3/you/want/to/delete
    

    The patterns mean "to checkout everything(*) except(!) the rest paths".

    Make it work:

    git checkout
    

    This way, these files are not checked out and everything is the same to you as long as you don't need to modify or checkout these files. In case you need these files to be checked out, remove or comment the file paths in .git/info/sparse-checkout and leave only *, and run git checkout again to checkout the hidden files.

提交回复
热议问题