MattS
MattS

Reputation: 138

Git - erase commit history and restore previous instance of repo?

Is it possible to completely erase commit history in Git, so that a commit cannot be seen, and restore the repository to the state it had at that point in time? If so, how can this be done, through the command line or otherwise?

Upvotes: 0

Views: 58

Answers (1)

Matthew Daly
Matthew Daly

Reputation: 9476

You can roll back to a specific commit and delete all later commits as follows:

git reset --hard <HASH>

where <HASH> is the commit you want to roll back to. Obviously use it with care!

If you then want to push it up to a remote that already has later commits you need to push with the --force flag to delete the later commits.

Upvotes: 2

Related Questions