Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I undo the last git push?

Tags:

git

A team member accidentally pushed half a gig of unwanted zips to the remote repo last night when they were in a rush. Yes... oops.

Nobody has pulled or committed since.

Ideally I want to just 'undo' what happened.

I have looked at filter-branch and was thinking of trying something like

git filter-branch --tree-filter 'rm -f *.zip' HEAD 

but that would be local, and I can't figure out how to do it direct on the remote repo.

Is there a simpler way to undo what happened? If she amends her last commit and pushes again will that undo the push - ie actually remove those files from the history?

Obviously if she deletes them, commits and pushes again then that still leaves the content in the repo, which is no good.

like image 970
Stray Avatar asked Jun 10 '10 08:06

Stray


People also ask

Can we undo last push in git?

To revert, you can: Go to the Git history. Right click on the commit you want to revert. Select revert commit.

Can we revert after push?

If you're sharing with others, don't go backwards, only ever go forwards. I think with the 2nd one you remove indeed the bad push in the remote repository BUT the history remains in your local repo. and when you do new changes, commit and push again, you will have again the bad push in the remote repo.

How do I remove last push from GitHub?

To remove the last commit from git, you can simply run git reset --hard HEAD^ If you are removing multiple commits from the top, you can run git reset --hard HEAD~2 to remove the last two commits.


1 Answers

Thanks Don, I'd seen that but somehow hadn't realised it fixed my problem, because I only have one branch.

I did:

git push -f origin 5910117a8fc2c71334251465b54d6d9daeb28d1c:master 

And it's all back to how it was.

like image 177
Stray Avatar answered Oct 09 '22 05:10

Stray