How to stop tracking and ignore changes to a file in Git?

前端 未结 20 1694
梦谈多话
梦谈多话 2020-11-21 07:17

I have cloned a project that includes some .csproj files. I don\'t need/like my local csproj files being tracked by Git (or being brought up when c

20条回答
  •  粉色の甜心
    2020-11-21 07:42

    There are 3 options, you probably want #3

    1. This will keep the local file for you, but will delete it for anyone else when they pull.

    git rm --cached or git rm -r --cached

    2. This is for optimization, like a folder with a large number of files, e.g. SDKs that probably won't ever change. It tells git to stop checking that huge folder every time for changes, locally, since it won't have any. The assume-unchanged index will be reset and file(s) overwritten if there are upstream changes to the file/folder (when you pull).

    git update-index --assume-unchanged 
    

    3. This is to tell git you want your own independent version of the file or folder. For instance, you don't want to overwrite (or delete) production/staging config files.

    git update-index --skip-worktree 
    

    It's important to know that git update-index will not propagate with git, and each user will have to run it independently.

提交回复
热议问题