Git, How to reset origin/master to a commit?

后端 未结 4 1938
我在风中等你
我在风中等你 2020-12-04 04:44

I reset my local master to a commit by this command:

git reset --hard e3f1e37

when I enter $ git status command, terminal says

4条回答
  •  感情败类
    2020-12-04 05:12

    Since I had a similar situation, I thought I'd share my situation and how these answers helped me (thanks everyone).

    So I decided to work locally by amending my last commit every time I wanted to save my progress on the main branch (I know, I should've branched out, committed on that, kept pushing and later merge back to master).

    One late night, in paranoid fear of loosing my progress to hardware failure or something out of the ether, I decided to push master to origin. Later I kept amending my local master branch and when I decided it's time to push again, I was faced with different master branches and found out I can't amend origin/upstream (duh!) like I can local development branches.

    So I didn't checkout master locally because I already was after a commit. Master was unchanged. I didn't even need to reset --hard, my current commit was OK.

    I just forced push to origin, without even specifying what commit I wanted to force on master since in this case it's whatever HEAD is at. Checked git diff master..origin/master so there weren't any differences and that's it. All fixed. Thanks! (I know, I'm a git newbie, please forgive!).

    So if you're already OK with your master branch locally, just:

    git push --force origin master
    git diff master..origin/master
    

提交回复
热议问题