I'm looking to write a Linux script that contributors can run to automate squashing and rebasing of their own branches/Pull Requests. As maintainer, I currently perform manual squashed merges of PRs, so have a clean history tree in master
but lose too much info about who committed what (e.g. for git blame
).
Other similar questions have accepted solutions which still allow for too much human error, e.g.
git rebase -i HEAD~3
requires people to count their commits every time.
git fetch origin && git rebase -i origin/master
requires manual changes of pick to squash.
The first solution above seems tempting to adapt, if we can reliably know the commit count based on output of another git command.
You can assume for now one author per PR and we want to squash it to one commit by that same author. The solution should also be able to work multiple times in a PR prior to merging. e.g. author may want to run it prior to raising the first PR, and then later after review and more commits, prior to merge. You can also assume that the implications of "rewriting history" with rebase are not of a concern.