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

前端 未结 2 1445
被撕碎了的回忆
被撕碎了的回忆 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:28

    You can try:

    git update-index --assume-unchanged -- unWantedFile
    rm unWantedFile
    # work
    # ...
    # later on
    git update-index --no-assume-unchanged -- unWantedFile
    git restore unWantedFile
    

    That should be enough to work in a working tree without that file, while telling Git the file is still there.

    It works too with git update-index --skip-worktree -- unWantedFile.
    I have written about the difference between the two here.

提交回复
热议问题