GIT: How to keep ignored files when switching branches?

后端 未结 3 1334
说谎
说谎 2021-01-02 13:52

I have an App.Local.config file which each developer has their own settings in. I do not want this file checked versioned in the GIT repo as every time it would be overwrit

相关标签:
3条回答
  • 2021-01-02 14:27

    Seems like this file was in index once. So its deletion is a change. You can add it to .gitignore or .git/info/exclude and then just recreate it on each developers machine.

    0 讨论(0)
  • 2021-01-02 14:30

    You should use git rm --cached App.Local.config not only in you working branch but also in the branch you want to switch to, or you will lose your App.Local.config when you switch back to the branch you worked if you only use git rm --cached App.Local.config in that branch.

    0 讨论(0)
  • 2021-01-02 14:33

    What probably happened is that you removed the file from your workspace but not from the index. If you did that git thinks that removing this file is a change and it will remove it from then on.

    The way to go is to remove the file you don't want to track anymore from the index with

    git rm --cached App.Local.config
    

    and then add that file to the .gitignore Doing that you will have no more problems with the file

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