Revert all commits by a specific author since spec

2019-03-26 14:50发布

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条回答
仙女界的扛把子
2楼-- · 2019-03-26 15:13

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"
查看更多
登录 后发表回答