Revert all commits by a specific author since spec

2019-03-26 15:07发布

问题:

I want to revert all commits by a specific author since 4 days ago. How do I do it?

To get all sha1s (with a bit of noise) I can use this:

git log --author=Mohsen --pretty=one --since=4.days

回答1:

You have to give format:%H to git log and use a loop:

for sha in `git log --pretty=format:%H --author=Mohsen --since=4.days`; do
  git revert --no-edit $sha
done

This will create one commit per revert. Suppress the --no-edit option to modify interactively the commit message on each revert.

Or, if you want to make one big revert commit:

for sha in `git log --pretty=format:%H`; do sharange="$sharange $sha"; done
git revert $sharange --no-commit
git commit -m "reverted commits $sharange"