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

后端 未结 11 1970
陌清茗
陌清茗 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:50

    A more generic solution:

    1. Edit .gitignore file.

      echo mylogfile.log >> .gitignore

    2. Remove all items from index.

      git rm -r -f --cached .

    3. Rebuild index.

      git add .

    4. Make new commit

      git commit -m "Removed mylogfile.log"

提交回复
热议问题