I have a bunch of old commits which I have already pushed. These are small changes 'e.g. typos', and I want to merge them together so that I don't have 100s of similar commits.
e.g. this:
7af8cee5715e266bf249891cf66f832cf8bb6606 typo 53104d19d1e2eba92baf36b8384100c461e417c1 typo 9e5afd2afc5d6051f568ce3a441eebf087c9ea46 typo fb8be7c9c54ae2d9ee3ed15971de49104729e4d6 ok 48828aaf959ee76d77a74dc35b8455542d0dbb8b fixed links 6387e73bd692024acbb67c1a843348dd6bd01bb8 fixed link baff3fc602faab37fbd0bf7df9c61ff367121985 fixed htaccess issue 2b3e66c19af49030a1da16f9fb7955c4d0f9aa3e fixed htaccess issue 5224690d2a44ec0c4872bedb3b54fb55af75530a fixed iplogging issue
Note: These are not directly behind the last commit, these are from months ago.
Your only option is to perform an interactive rebase on the commits and force-push the rewritten commits to the server-side repository. I recommend you keep the history as-is if the commits since then contain merge commits.
522469
.git log --oneline --merges 522469~1
. If this generates output, do not run the interactive rebase.git rebase --interactive 522469~1
522469
that you may reorder. Change thepick
command (first column) to eithersquash
orfixup
for commits you want to meld.squash/fixup
to your heart's content, save the file and close the editor.git push --force origin HEAD
Some things to keep in mind:
git rebase --interactive
if #2 generated output.HEAD
). Any branches based off of any commits in the editor window (git branch --contains 522469
) will need to be rebased off their rewritten counterparts. So there might be more work involved than displayed above. Checkgit rebase --onto
.git commit --amend
to rewrite theHEAD
commit instead of creating a new commit. Another option is togit rebase --interactive
with less commits (e.g. not from months ago but say 2 hours ago,HEAD~10
) which might present less potential for conflicts.