13

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?

Dan Bolser
  • 871
  • 1
  • 9
  • 17
  • It's rare to really need to wipe out a commit. Just add other commits that fix your repo and brings it to the state you want it to be. (Unless of course you've done something like committed and pushed up passwords or the like). – dkinzer Sep 18 '13 at 14:23
  • 1
    I agree with @dkinzer The operation in the answer works, but it is one of those operations that you should have a clear answer as to why you are using versus just adding a new commit. As with any destructive operation. – usumoio Sep 18 '13 at 15:06
  • possible duplicate of [How to revert initial git commit?](http://stackoverflow.com/questions/6632191/how-to-revert-initial-git-commit) – Maic López Sáenz Sep 19 '13 at 13:34

2 Answers2

20

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
Maic López Sáenz
  • 10,385
  • 4
  • 44
  • 57
1

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

git commit --amend
git push --force origin
TheKojuEffect
  • 20,103
  • 19
  • 89
  • 125