Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove sensitive data but not file from git history [duplicate]

I have a file that once contained sensitive config information. I move that config info out into another file that isn't under version control. I want to keep the other file under version control, but I want to remove its history because one can easily browse the source on github and find the sensitive information in previous commits. What's the best way to do this? I'm only seeing how to remove the file itself from version control and clear its history.

A little new to git, so pardon the newbieness.

like image 776
Tyler Avatar asked Mar 21 '13 01:03

Tyler


People also ask

How do I remove sensitive information 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 clean up my commit history?

Steps to get to a clean commit history:understand rebase and replace pulling remote changes with rebase to remove merge commits on your working branch. use fast-forward or squash merging option when adding your changes to the target branch. use atomic commits — learn how to amend, squash or restructure your commits.

Does git keep copies of files?

In Git, as with most version control systems, a repository retains a complete copy of the entire project throughout its lifetime. However, unlike most other VCSs, the Git repository provides not only a complete working copy of all the files in the repository but also a copy of the repository itself with which to work.

Can you rewrite git history?

There are many ways to rewrite history with git. Use git commit --amend to change your latest log message. Use git commit --amend to make modifications to the most recent commit. Use git rebase to combine commits and modify history of a branch.


1 Answers

You might want to look at this article https://help.github.com/articles/remove-sensitive-data

Pretty much says this command

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

Will remove the history of Rakefile from git. However, they go ahead and add that file to their gitignore. You should probably skip that part since you want to keep the file in version control.

like image 120
Leo Correa Avatar answered Oct 05 '22 06:10

Leo Correa