You could follow these steps to revert the incorrect commit(s) or to reset your remote branch back to correct HEAD/state.

1.checkout the remote branch to local repo.

git checkout your_branch_name

2.copy the commit hash

(i.e. id of the commit immediately before the wrong commit) from git log

git log -n5

should show something like this:

commit 7cd42475d6f95f5896b6f02e902efab0b70e8038 "Merge branch 'wrong-commit' into 'your_branch_name'"
commit f9a734f8f44b0b37ccea769b9a2fd774c0f0c012 "this is a wrong commit" 
commit 3779ab50e72908da92d2cfcd72256d7a09f446ba "this is the correct commit"

3.reset the branch to the commit hash copied in the previous step

git reset <commit-hash> (i.e. 3779ab50e72908da92d2cfcd72256d7a09f446ba)

4.run the git status to show all the changes that were part of the wrong commit.

5.simply run git reset --hard to revert all those changes.

6.force-push your local branch to remote and notice that your commit history is clean as it was before it got polluted.

git push -f origin your_branch_name

The end.

相关文章:

  • 2021-12-23
  • 2021-09-25
  • 2022-12-23
  • 2022-12-23
  • 2021-12-03
  • 2021-10-25
  • 2021-11-06
  • 2021-05-04
猜你喜欢
  • 2021-07-02
  • 2021-07-13
  • 2021-08-08
  • 2022-12-23
  • 2022-12-23
  • 2022-01-21
  • 2022-01-04
相关资源
相似解决方案