-2

I've been committing changes inside my GitHub repo. I now want to roll back to a certain commit that I've made sometime ago.

How do I reset my repo so that all the commits I've made, after the one i'd like to go back to, are wiped?

I've found some answers regarding git reset --hard <id> but it's not doing what I want.

Regentix
  • 293
  • 1
  • 4
  • 14
  • Why do you want to do that? Why can't you just push some older state of your code into it? In other words, why do you want to "rewrite the history" ? It is possible, but it is socially bad taste! – Basile Starynkevitch Jun 17 '18 at 17:17
  • I know that resetting to a certain commit is bad practice, but I really needed to. Thanks for the heads up though. – Regentix Jun 17 '18 at 17:23
  • But why? We all make mistakes, and several people could have `git pull`-ed your code so are still keeping your old code. I feel it is bad taste... Consider (like we all do) take responsability for your past mistakes. Play with branches. – Basile Starynkevitch Jun 17 '18 at 17:24
  • I've added code but realized that it wasn't going to work out as planned. And yes, if it were a group project, I wouldn't even consider doing what I just did. – Regentix Jun 17 '18 at 17:27
  • 1
    That is what branching is for. Learn to use it. No need to "rewrite history". And perhaps you'll notice in the future that some lines from that bad code might be wisely reused – Basile Starynkevitch Jun 17 '18 at 17:29

1 Answers1

2

You need to "force push" the commit to the repository.

git reset --hard <id>
git push --force-with-lease

Please be aware that this wipes data from the remote repository and everyone who already has pulled your repository needs to revert back, too.

Lienhart Woitok
  • 426
  • 3
  • 10