git discard all changes and pull from upstream

前端 未结 5 1092
迷失自我
迷失自我 2021-01-29 17:59

How do I fetch upstream repo and make it replace master? I only have one branch on my repo, which is master, and I completely messed it up, so I basically need to start over fro

5条回答
  •  说谎
    说谎 (楼主)
    2021-01-29 18:33

    There are (at least) two things you can do here–you can reclone the remote repo, or you can reset --hard to the common ancestor and then do a pull, which will fast-forward to the latest commit on the remote master.

    To be concrete, here's a simple extension of Nevik Rehnel's original answer:

    git reset --hard origin/master
    git pull origin master
    

    NOTE: using git reset --hard will discard any uncommitted changes, and it can be easy to confuse yourself with this command if you're new to git, so make sure you have a sense of what it is going to do before proceeding.

提交回复
热议问题