0

I have made some error with my latest commit to my github repo. How can i delete tha latest one?

Do i use this command:

git reset --hard HEAD^

for remove the latest one?

and then:

git push origin master

for update?

or should i use a another command?

Johan
  • 41
  • 2

3 Answers3

2

Yes, it is possible to reset and force push, but you should only do this if you are working alone on your repository.

When pushing a commit to a public/shared repository, that commit is cloned by others into their repositories and will therefore potentially find it's way back to the repository.

The best way is simply to revert your commit using git revert HEAD. This creates another commit, which simply undoes your last commit.

The rule is: If you did not publish your commit yet, a reset is fine, but if you already published (i.e. pushed) your commit, a revert is the safe way.

michas
  • 25,361
  • 15
  • 76
  • 121
0

Basically, yes. You may need

git push --force origin master

since it will generally refuse an update that isn't a descendant of the current remote HEAD, but it won't hurt to try your way first and see what it complains about.

Useless
  • 64,155
  • 6
  • 88
  • 132
0

I would go with git reset --soft HEAD~1 to keep the files in the index. By doing this, you can modify the erronous files and commit again.

ogzd
  • 5,532
  • 2
  • 26
  • 27