Remove a file from a Git repository without deleting it from the local filesystem

后端 未结 11 2189
陌清茗
陌清茗 2020-11-22 02:25

My initial commit contained some log files. I\'ve added *log to my .gitignore, and now I want to remove the log files from my repository.



        
11条回答
  •  天涯浪人
    2020-11-22 02:46

    From the man file:

    When --cached is given, the staged content has to match either the tip of the branch or the file on disk, allowing the file to be removed from just the index.

    So, for a single file:

    git rm --cached mylogfile.log
    

    and for a single directory:

    git rm --cached -r mydirectory
    

提交回复
热议问题