1

I know how to revert to previous commit. But now I did a lot of work since I committed and I want to restart and start from scratch straight from my current commit.

How do I do that?

kowsky
  • 12,647
  • 2
  • 28
  • 41
Contentop
  • 1,163
  • 3
  • 20
  • 43
  • 1
    If you want to get rid of all of your local changes `git reset --hard HEAD`. WARNING: NO WAY TO RECOVER LOST FILES. – EncryptedWatermelon May 06 '19 at 17:46
  • 1
    github != gitlab != bitbucket (doubt your repository has origins on all three). Also, even if you need to force push, the git server software may be irrelevant. – crashmstr May 06 '19 at 17:54
  • Possible duplicate of [How do I revert all local changes in Git managed project to previous state?](https://stackoverflow.com/questions/1146973/how-do-i-revert-all-local-changes-in-git-managed-project-to-previous-state) – kowsky May 06 '19 at 18:27

3 Answers3

3

git reset --hard is the easiest one... but it does get rid of everything that's hanging around. You might also consider just saving it in the stash and dump it later on when you are sure you won't need it anymore.

git stash push -m "Saving this in case I want to use it later on"

That will clean up the working tree.

eftshift0
  • 26,375
  • 3
  • 36
  • 60
1

The latest commit in the current branch is referenced by HEAD, you could just git reset to it:

$ git reset HEAD --hard
Mureinik
  • 297,002
  • 52
  • 306
  • 350
1

If you have created new files or directories that you need to get rid of, you can also use git clean -fd to remove those.

To revert changes in tracked files you can do git reset --hard which will remove all new code since your last commit.

Tim Smith
  • 56
  • 2