0

I have internal github in our organization. There is a particular git repo where I need to replace a sensitive string from all commits. There are around 2000 commits and the sensitive string is there from first commits. There are 7 valid branches as well. How can I delete/replace the sensitive string from all commits. I dont have internet access for the machine nor I have privileges to download bfg repo cleaner tool. I am trying my luck with git filter-branch command below. But this has not helped yet.

git filter-branch -f --msg-filter 'sed "s/sensitivedata/noman/g"' -- --all

If nothing works my last resort is to delete the repo and create new one. But before doing that I wanted to see if I have an option preserving existing commits. Any help and light towards this is highly appreciated.

1

1 Answer 1

0

I was facing the similar problem. Try using below script, it worked for me.

# Replace "sensitivedata" with "noman" in all commits across specified branches
branches=("branch1" "branch2" "branch3")  # Add all valid branch names
for branch in "${branches[@]}"; do
    git checkout "$branch"
    git filter-branch -f --tree-filter 'find . -type f -exec sed -i "s/sensitivedata/noman/g" {} +' -- --all
done

Sign up to request clarification or add additional context in comments.

2 Comments

I was able to delete the commits from git, but somehow github and the URL for gitrepo from browser still shows the deleted commits and its messages. How can this be removed?
When you perform a history rewrite with git filter-branch, the rewritten history is present in your local repository, but it may not automatically sync with GitHub or other remote repositories. To update the remote repository with the rewritten history, you'll need to force push the updated branches.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.