Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete a commit from github [duplicate]

Tags:

git

github

commit

Possible Duplicate:
How can I remove a commit on github?
How to delete a 'git commit'

So I'm trying to remove a commit from github.

It is 3 commits ago and I'm ok if all the changes are lost.

So based on questions from here, I did a

git reset --hard <sha-commit-name-to-go-back-to>
git push -f origin HEAD^:master

Now it is gone from github as well as in git log.

I then redid my changes and did

git add <file I changed>
git commit
git log

Everything looks fine. There's no trace of the old commits. So I finally did a:

git push

Now suddenly github has those three commits that I had removed.

What am I doing wrong? How to I keep the commits from returning?

like image 327
Jistanidiot Avatar asked May 30 '12 14:05

Jistanidiot


People also ask

How do I remove a repeated commit in git?

If you want to clean things up, then the thing to do is a git rebase --interactive and remove the merge commits.

Can I delete a commit in 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 HEAD~2 to remove the last two commits. You can increase the number to remove even more commits.


1 Answers

Use git rebase process before applying new changes. After rebasing add the new changes and commit.

git rebase -i HEAD~2

git push origin +master
like image 96
Aneesh Narayanan Avatar answered Sep 23 '22 20:09

Aneesh Narayanan