Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to undo the initial commit on a remote repository in git?

If my very first commit is wrong, yet pushed to a (currently private) remote, how do I undo that commit on the remote?

I'm guessing I can just amend and then push --force?

like image 239
Dan Bolser Avatar asked Sep 18 '13 14:09

Dan Bolser


People also ask

How do I remove a specific commit from a remote?

To delete commits from remote, you can use the git reset command if your commits are consecutive from the top or an interactive rebase otherwise. After you delete the commits locally, push those changes to the remote using the git push command with the force option.


2 Answers

By deleting your HEAD you can restore your repository to a new state, where you can create a new initial commit:

git update-ref -d HEAD

After you create a new commit you will need to force it to the remote in order to overwrite the previous initial commit:

git push --force origin
like image 110
Maic López Sáenz Avatar answered Oct 03 '22 17:10

Maic López Sáenz


If you've just one commit (initial commit), you can do as

git commit --amend
git push --force origin
like image 40
TheKojuEffect Avatar answered Oct 03 '22 17:10

TheKojuEffect