Search code examples
pythonbashgitgit-commitgit-revert

Telling if Git commit is a revert commit


I would like to build a script that pulls simple statistics from my repository. I would like to exclude merge commits and revert commits from those statistics.

There was a question asked 8 years ago about distinguishing between regular commit and merge commit:

Telling if a Git commit is a Merge/Revert commit

The answer is great when it comes to merge commit (i.e. the commit that has more than one parent) but there is no satisfactory answer for distinguishing if commit is a revert commit.

I'm looking at GitPython package and can't find anything on their documentation that would help.

Any help would be greatly appreciated.

Alternatively if there is something already out there (either script/library/product) that helps with git statistics (and excludes merge commits and revert commits) I would also accept such answer.


Solution

  • A "revert commit" isn't a special entity in git. It's a cli feature meant to make it simple to rollback a previous commit(s) without rewriting the history.

    It's just a regular commit with a reverted diff of the the commit(s) to be reverted. There is no chance to identify such a revert commit automatically.