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

前端 未结 20 1712
梦谈多话
梦谈多话 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 08:02

    one line answer git update-index --assume-unchanged [path]

    Use this whenever you have a file that is in central repo and also local repo.you need to make changes in that file but must not be staged/committed to the central repo. This file should not be added in .gitignore. because new changes in the file if introduced by system administrators, senior developers needs to be distributed among all local repos.

    Best Example: config file for DB connections. In a central repo, you will have all the username,password, host,port with values of a production DB server. But in local dev, you should use only a local or any other development DB server(that your team has setup). In this case you wanna make changes in config file but should not be committed to central repo.

    Best

    0 讨论(0)
  • 2020-11-21 08:02

    after search a long time , find a way do this . alias a git command in .gitconfig.like in android studio project,before checkout branch revert config file and then skip it ,after checkout branch use sed change config file to my local config. checkoutandmodifylocalproperties = !git update-index --no-skip-worktree local.properties && git checkout local.properties && git checkout $1 && git update-index --skip-worktree local.properties && sed -i '' 's/.*sdk.dir.*/sdk.dir=\\/Users\\/run\\/Library\\/Android\\/sdk/g' local.properties && :

    0 讨论(0)
提交回复
热议问题