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

后端 未结 11 2178
陌清茗
陌清茗 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 03:02

    Git lets you ignore those files by assuming they are unchanged. This is done by running the git update-index --assume-unchanged path/to/file.txt command. Once marking a file as such, git will completely ignore any changes on that file; they will not show up when running git status or git diff, nor will they ever be committed.

    (From https://help.github.com/articles/ignoring-files)

    Hence, not deleting it, but ignoring changes to it forever. I think this only works locally, so co-workers can still see changes to it unless they run the same command as above. (Still need to verify this though.)

    Note: This isn't answering the question directly, but is based on follow up questions in the comments of the other answers.

提交回复
热议问题