David542
David542

Reputation: 110472

Git reset permanently

I made some errors in my code and I need to do the following to reset it:

git reset --hard 0adf6cdaa45af6b0520de1a54d027be5f1a84f06

I also want to remove everything that has been committed after that. How would I do this to permanently reset the repository to this? That is, if I do $ git pull origin production, I want nothing to happen because the repository is 'at' the reset position.

Upvotes: 1

Views: 432

Answers (3)

Aparna
Aparna

Reputation: 255

Use git reset --hard 0adf6cdaa45af6b0520de1a54d027be5f1a84f06 to revert your code to your correct last commit. But, you need to make sure that every1 working in your project must take pull after your action.

Upvotes: 0

Andreas Wederbrand
Andreas Wederbrand

Reputation: 40061

You need to push a new HEAD to github. I'm not sure it's allowed but it's called a forced push (search for --force).

git push --force

Make sure that all other developers that have this repository checked out do git pull after you've pushed. If they start to develop after a commit you've thrown away things will go bad.

Upvotes: 1

Alex Nolasco
Alex Nolasco

Reputation: 19476

I am assuming you are working by yourself and you have the luxury to discard all commits after that SHA1. Then you can overwrite history with git push force. Next time you do a git pull origin production, you should be 'at' the reset position.

git push --force

See also: Force "git push" to overwrite remote files

Upvotes: 2

Related Questions