Throw away local commits in Git

前端 未结 20 1616
遥遥无期
遥遥无期 2020-12-02 03:08

Due to some bad cherry-picking, my local Git repository is currently five commits ahead of the origin, and not in a good state. I want to get rid of all these commits and st

相关标签:
20条回答
  • 2020-12-02 04:03

    For those interested in the Visual Studio solution, here is the drill:

    1. In the Team Explorer window, connect to the target repo.
    2. Then from Branches, right-click the branch of interest and select View history.
    3. Right-click a commit in the History window and choose Reset -> Delete changes (--hard).

    That will throw away your local commits and reset the state of your repo to the selected commit. I.e. Your changes after you pulled the repo will be lost.

    0 讨论(0)
  • 2020-12-02 04:05

    Simple Solution will be to match local master branch HEAD to origin/master branch HEAD

    git reset --hard origin/master
    

    PS: origin/master - is remote pointer to master branch. You can replace master with any branch name

    0 讨论(0)
提交回复
热议问题