David Brower David Brower - 2 months ago 6x
Git Question

Squash Commits Based On Author

In a repository there are a very large number of commits caused by automated build-tool updates to AssemblyInfo files (the project is in C#). These commits all have "Dev BuildAgent" as an author.

Is there any way to squash all commits in a repository from a specific author into the first child from another author?

Of course, one possibility would be to run

git rebase --interactive
using the SHA of the root commit and manually go through the list of commits and apply the squash command to the appropriate commit manually. However, it would be useful to know whether there is a quicker option, bearing in mind there are a very large number of commits.


To squash all commits of the author with email foo@bar.com into the next child commit of another author, you can use the following. You can of course also check any other attribute like author name, commiter email, committer name, ...

git filter-branch --commit-filter '[ "$GIT_AUTHOR_EMAIL" = "foo@bar.com" ] && skip_commit "$@" || git commit-tree "$@"'