Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete commit that is pushed to the remote repository?

Tags:

git

A local branch:-

'feature/100'

And Remote branches:-

'master'

'Version2'

Accidently,

  1. I have merged my feature branch 'feature/100' to the master
  2. Also pushed it to the remote repository.

But in real 'feature/100' should have been merged into remote branch 'Version2'

How I fixed it (partially):-

i have merged the feature branch 'feature/100' to the remote branch 'Version2' and pushed it to the server.

git checkout Version2
git merge --squash feature/100
git add .
git commit -m 'New message'

But I want to delete the last push I have merged and commit to the master branch. How?

Side Note I am only one working on this project.. So even if pushed commit is deleted it won't harm anyone else

like image 698
user1327064 Avatar asked Sep 06 '12 17:09

user1327064


People also ask

Can you undo a commit after push?

You can always drop the latest revert commit (which reverts the oldest commit) with g reset --hard HEAD~ . To find out the hash of the commit(s) you can use git log . Look at the git-revert man page for more information about the git revert command.


1 Answers

It's probably too late, but if you want to rewind your pushed branch (master?) by one commit, issue the following command:

git push origin +master^:master

+ makes the push forced, master^ describes the previous-last commit. :master pushes to the remote master branch.

like image 128
knittl Avatar answered Nov 12 '22 17:11

knittl