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
Steps to revert a Git commitLocate the ID of the commit to revert with the git log or reflog command. Issue the git revert command and provide the commit ID of interest. Supply a meaningful Git commit message to describe why the revert was needed.
We can use the git revert command for reverting multiple commits in Git. Another way of reverting multiple commits is to use the git reset command.
Update the author details of historical commitsCheck through the commits in the list, and hit ctrl+x , followed by enter to apply the changes.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With