-1

I'm a solo developer learning Git/hub. There is only one branch in my repo "round-robin". I would like to remove the last two commits from history, as in leave no trace they ever existed. I'd like to remove it from Github.

Once the two most recent commits are removed, I'd like to push my current local source code that is now working.

I've tried a hard reset, it didn't work. I even tried an experiment of deleting the file on github and it still didn't work somehow.

Celeritas
  • 14,489
  • 36
  • 113
  • 194

1 Answers1

1

You have to use the --force flag.

git reset --hard HEAD~2
git push --force

Note that forcing a push is most likely a bad idea when you are collaborating with other developers.

Daniel Hepper
  • 28,981
  • 10
  • 72
  • 75
  • I had done this but I think because the local copy contains the mistake, when I push it the next time the remote repo now has back all the wrong history. – Celeritas Jun 13 '16 at 13:10
  • That doesn't sound right. Please post the history and mark the commits you want to remove. – Daniel Hepper Jun 13 '16 at 13:13
  • I got it to work, but on github it still shows, where the red lines indicate removals, the old things I want to erase from history. – Celeritas Jun 13 '16 at 13:42
  • If nothing works.. You could download a previous commit to your desktop. Erase everything online and push your local code – warkentien2 Jun 13 '16 at 15:57
  • @warkentien2 that's pretty much what I always do anyways. I'm just learning git as lots of jobs require it but it boggles me why a tool that's supposed to increase productivity is so difficult to use and has complexities that usually are detrimental to what the goal is: isn't git supposed to make version control easier? – Celeritas Jun 14 '16 at 01:58
  • 1
    @Celeritas I agree. But the problem here is GitHub, not git. That's why some companies are trying to fix this problem, like GitKraken. – warkentien2 Jun 14 '16 at 02:01
  • @warkentien2 I took a look and must say GitKraken has an amazing UI. So GitKraken isn't a replacement to Git or Github, but something that sits in between, do I understand correctly? – Celeritas Jun 14 '16 at 02:35
  • @Celeritas there's also a GitHub desktop. It's a UI for managing Git repos. Not sure how exactly they work. Most developers don't use them. But designers love it. – warkentien2 Jun 14 '16 at 02:44