Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Revert all commits by a specific author since specific time

Tags:

git

git-revert

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
like image 660
Mohsen Avatar asked Jul 29 '13 23:07

Mohsen


People also ask

How do you hard revert to a specific commit?

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.

Can I git revert multiple commits?

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.

How do I change the author of multiple commits?

Update the author details of historical commitsCheck through the commits in the list, and hit ctrl+x , followed by enter to apply the changes.


1 Answers

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"
like image 58
CharlesB Avatar answered Oct 26 '22 23:10

CharlesB