Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to revert a 'git filter-branch -f --env-filter'

I am quite a newb regarding git and usually git commit, pull and push are the only commands I do. Recently noticed that my commits were set to a default name and email and wanted to change it. Stupidly I ran this which I found in a post somewhere:

git filter-branch -f --env-filter "GIT_AUTHOR_NAME='Newname'; GIT_AUTHOR_EMAIL='newemail'; 
GIT_COMMITER_NAME='Newname'; GIT_COMMITTER_EMAIL='newemail';" HEAD

I thought this would change only my commits, but instead it changed all commits in the repo to have my name and email. Of course to continue my "dumbness" I pushed the changes.

Also I seem to have lost history and all commits on github seem to have a duplicate entry as well. One with my name and email and the original one.

Is there a way to revert this? Maybe using a copy of a previous pull to push the original info?

like image 806
Joao Jesus Avatar asked Jan 17 '23 21:01

Joao Jesus


2 Answers

If you haven't done anything to clean up loose objects after you did the filter-branch command, you can reset your master branch (assuming HEAD was master when you gave the command):

git reset --hard refs/original/master
like image 169
ralphtheninja Avatar answered Jan 19 '23 10:01

ralphtheninja


If you didn't cleanup yet you can reset your branch with : git reset --hard refs/original/master this will reload all the original files prior to your attempt then do:

git filter-branch -f --env-filter "GIT_AUTHOR_NAME='Newname'; GIT_AUTHOR_EMAIL='newemail'; GIT_COMMITER_NAME='Newname'; GIT_COMMITTER_EMAIL='newemail';" "--tag-name-filter cat -- --all"

like image 31
Learath2 Avatar answered Jan 19 '23 11:01

Learath2