Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 316
David Brower Avatar asked Oct 29 '22 22:10

David Brower


1 Answers

To squash all commits of the author with email [email protected] 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" = "[email protected]" ] && skip_commit "$@" || git commit-tree "$@"'
like image 176
Vampire Avatar answered Nov 15 '22 06:11

Vampire