Change git history of PR merged long time ago from commit method to squash method

68 Views Asked by At

Hello to the community!

As you can see in the diagram there is a commit (cm1) that includes a lot of binary files that was committed in a local branch. This commit was reverted at cm2 and at the final commit (cm4) a Pull Request was created and merged with the commit method 6 months ago. This means that master branch will include the history of this development branch.

The result of this is to be unable to clone the repository due to this commit, so I have to rewrite the history.

I have tried the above command, but somehow it make changes like removing or keeping the next PRs. It is like messing up the commits.

git filter-branch --index-filter 'git rm -r --cached --ignore-unmatch make/*' <hash_cm1>..HEAD

An other idea that I thought, and here I would like your contribution, is if I can change the history of this merge and from merge commit method to convert it to merge squash method. Which means to squash cm1,cm2,cm3,cm4 in order to get rid of the existance of binaries from cm1 and have one commit for this PR.

Thank you in advance!

git

1

There are 1 best solutions below

0
On

I found the solution to my problem.

The easiest and quicker solution is using tool bfg-repo-cleaner.

java -jar bfg.jar --delete-files BIG_FILE  my-repo.git
git reflog expire --expire=now --all && git gc --prune=now --aggressive
git push --force

Mind to take a repository backup first with git clone --mirror

For now I see that there is no corruption and worked very well.

Amazing tool!

[EDIT] Seems that only master has changed, and the rest branches contain the binary files...