如何删除git中单个文件的所有痕迹

时间:2014-01-19 03:56:35

标签: git

我最近注意到我在git中的版本控制下有一个包含敏感信息的文件。我现在已将此文件添加到我的.gitignore列表中,但是如何从我的提交历史中删除所有提及它而不触及任何其他内容?即,我不想删除我的.git目录。

2 个答案:

答案 0 :(得分:2)

答案 1 :(得分:1)

在GitHub帮助网站上试用本指南:https://help.github.com/articles/remove-sensitive-data

具体做法是:

git filter-branch --force --index-filter \
  'git rm --cached --ignore-unmatch Rakefile' \
  --prune-empty --tag-name-filter cat -- --all