How to stop tracking a file without removing it from repo

后端 未结 4 1138
醉话见心
醉话见心 2021-01-30 11:11

I have a config file which I want to keep on the remote repository, but I don\'t want to track its changes on my computer. Adding it to .gitignore doesn\'t do the trick.

<
相关标签:
4条回答
  • 2021-01-30 11:21

    You will need to do the combination of .gitignore file and git rm --cached. Use the following command :

    git rm --cached filename.txt

    This will remove the file from indexing but it will keep it in your repository and working area. After applying rm --cached you will need to commit the changes for it to take effect. It will show as Deleted in your tracked changes, but that's only because it has been deleted from indexing. Note: If you make changes to it again in future commits you will have to run: git rm --cached to untrack the changes to the file from the particular commit.

    0 讨论(0)
  • 2021-01-30 11:23

    If that's the case then you shouldn't have the file versioned at all; you should version a template of the file. For example, if the configuration file is foo/config.txt then you should have a versioned foo/config.txt.template in the repository with example (or blank) configuration settings. foo/config.txt should not be in the repository at all, and should be ignored with .gitignore.

    Then, in a new clone, you just copy foo/config.txt.template to foo/config.txt and alter the settings as appropriate.

    0 讨论(0)
  • 2021-01-30 11:23

    You could commit all the other files, and for the changes to the local configurations alone, you could use the 'stash' feature that git provides.

    0 讨论(0)
  • 2021-01-30 11:26

    If you want to temporarily stop tracking a file, you can still use

    git update-index --assume-unchanged <file>
    // track changes again :
    git update-index --no-assume-unchanged <file>
    
    0 讨论(0)
提交回复
热议问题