#!/usr/bin/env bash # The commit you want to revert to (exclusive) TARGET_COMMIT=5e7794646a4dce935b27541d60aa9084574ba6b8 # Revert all commits from HEAD back to TARGET_COMMIT for commit in $(git rev-list --reverse $TARGET_COMMIT..HEAD); do git revert --no-commit $commit done git commit -m "Reverted to state before $TARGET_COMMIT"