Good evening.

After the introduction of a new security policy in the company, they asked to clean the list of files from commits (files can be stored locally, but not be accessible via git BitBucket).

How to "clear" all traces about the contents of files from the git repository?

Reported as a duplicate by D-side , LEQADA , Community Spirit 2 Feb '18 at 0:28 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • 2
    If only remove the entire repository with BitBucket. It is only interesting how you will exchange changes in this situation. Is it possible to launch your own Git-server within the company's network? .. - D-side
  • one
    Ahh. Stop. By "file list" was meant "some of the files in the repository"? In this case, no, repository is not necessary to delete, of course. This is, potentially, a complete rewriting of history through some filter-branch , and similar questions have already been raised here 100%. - D-side
  • @ D-side it was, flooded with Atlssian public now need to be cleaned. - Hellseher

2 answers 2

If you need to delete a file from a remote repository, use the command

 git rm --cached mylogfile.log 

To remove a directory from a remote repository

 git rm --cached -r mydirectory 

After that, commit and run the changes to the repository. If they remain in the local repository, they will be deleted from the remote repository.

  • Did someone say the repository was deleted? He is, he is there. You only need to get rid of some, perhaps quite ancient Comitos with secret files - LEQADA
  • Remote repository - this is not locally deployed, but on some server. - Nikolaj Sarry
  • Oh, now I understand. Your answer is still not what the author needs. He wants to delete all actions associated with a specific file. It is possible that the file was added a very long time ago and changed every day. - LEQADA
  • @LEQADA needs to clear the BitBucket repository of the company, leaving the files on the server in the office untouched. - Hellseher
  • You are the only way to remove it from the new commit. Consider a piece of paper covered only and not removed. Whoever needs will always be able to look into early commits and find secret files there. - Nick Volynkin

git bash

git log --pretty=format: --name-status | grep -i ^D | cut -f2- | sort -u | xargs -I {} git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch {}' HEAD 

Just delete all deleted files from commits. It will take a decent time to perform if there are a lot of commits. If you want to optimize the team, then dare.