Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove file from Git history?

Tags:

git

github

Some time ago I added info(files) that must be private. Removing from the project is not problem, but I also need to remove it from git history.

I use Git and Github (private account).

Note: On this thread something similar is shown, but here is an old file that was added to a feature branch, that branch merged to a development branch and finally merged to master, since this, a lot of changes was done. So it's not the same and what is needed is to change the history, and hide that files for privacy.

like image 809
Marcos R. Guevara Avatar asked May 03 '17 14:05

Marcos R. Guevara


People also ask

Can you remove a file from git history?

If you commit sensitive data, such as a password or SSH key into a Git repository, you can remove it from the history. To entirely remove unwanted files from a repository's history you can use either the git filter-repo tool or the BFG Repo-Cleaner open source tool.

How do I remove files from git log?

Remove a file from Git commit historyhtml" file from the repository and go from there until we push the deletion to the master origin. then by running the git status command, you should find that Git has deleted the file and staged the deletion to be committed as shown in the next screenshot.


1 Answers

I have found this answer and it helped:

git filter-branch --index-filter \     'git rm -rf --cached --ignore-unmatch path_to_file' HEAD 

Found it here https://myopswork.com/how-remove-files-completely-from-git-repository-history-47ed3e0c4c35

like image 197
Petro Franko Avatar answered Oct 11 '22 09:10

Petro Franko