문제

I have committed a file that shouldn't be in a git repository. I have deleted it and committed the deletion, but I can still access the file via the git history.

How do I delete a committed file permanently, so that there is no trace of it?

도움이 되었습니까?

해결책

You can remove permanently a file using filter-branch. It will apply the command in argument in every revision of your repository.

git filter-branch --tree-filter 'rm -rf your_file' HEAD

This detailed post might help you. The git doc is pretty helpful too.

As mentioned in the comments, you will also need a git gc to clean your local commits and then git pushto update your remote repository.

다른 팁

This might help:

https://help.github.com/articles/remove-sensitive-data

The following command will do this:

git clone https://github.com/defunkt/github-gem.git
# Initialized empty Git repository in /Users/tekkub/tmp/github-gem/.git/
# remote: Counting objects: 1301, done.
# remote: Compressing objects: 100% (769/769), done.
# remote: Total 1301 (delta 724), reused 910 (delta 522)
# Receiving objects: 100% (1301/1301), 164.39 KiB, done.
# Resolving deltas: 100% (724/724), done.

cd github-gem

git filter-branch --force --index-filter \
  'git rm --cached --ignore-unmatch Rakefile' \
  --prune-empty --tag-name-filter cat -- --all
# Rewrite 48dc599c80e20527ed902928085e7861e6b3cbe6 (266/266)
# Ref 'refs/heads/master' was rewritten

This command will run the entire history of every branch and tag, changing any commit that involved the file Rakefile, and any commits afterwards. Commits that are empty afterwards (because they only changed the Rakefile) are removed entirely. Note that you'll need to specify the full path of the file you want to remove, not just its filename.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top