Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I revert a push to repository in GitHub

Tags:

git

I commited few changes, and made a push to remote branch in github. But then I realized that I did some mistakes in the commit, and pushed lot of wrong files. Is there a way to revert the push?

like image 953
user2916464 Avatar asked Nov 07 '13 01:11

user2916464


1 Answers

The git revert command does not rewrite history, but does take away the changes from a commit with a new commit. Then all you would have to do is to push again. This is the suggested method.

If you really want to make github look like a particular commit never really happened, there is a way, but use caution (especially if other users contribute to the github repository). In fact if others use this github repository, stop now and use the method mentioned in the first paragraph.

If this is your own private github repository and the last push is what you need to take away (assumes you are still on the same local branch):

git reset --hard HEAD~
git push -f

If it is not the last push, see man pages for either git cherry-pick, or git rebase to get your local directory to match what you want github to look like before doing the git push -f. If you do not supply the -f option to git push, you will not rewrite history. And any push will fail if it attempts to rewrite history. The -f option should not be used by default.

like image 81
cforbish Avatar answered Oct 18 '22 08:10

cforbish