Ad

Recommended Way With Git To Go Back To A Previous Commit

- 1 answer

Hy,

I have some commits in my local repository in GIT(commit1, commit2 and commit3).The remote repository is updated with the last commit3. Now I noticed the commit2 and commit3 introduces some bugs and I want go back to commit1. I used a reset commit1 but after I cannot push because the head in the local branch is older than the remote branch and git says I need to update so

  1. What is the recommended way to do it according to GIT, using reset, checkout...?

Thanks

Ad

Answer

If you are sure you want to destroy this 2 commits in the remote repository and annoying all the devs that already fetch them, you just have to do a force push after the reset you did :

git push origin master --force-with-lease 

If origin is your remote and master your local branch...

Ad
source: stackoverflow.com
Ad