How can I pull down a commit from Github (Enterprise) that I don't have locally?

前端 未结 3 538
滥情空心
滥情空心 2021-02-05 19:46

I accidentally did a push --force on the wrong repo (too many termminals open), effectively resetting the master branch back to an earlier commit.

Looking a

3条回答
  •  囚心锁ツ
    2021-02-05 20:05

    I understand currently you don't have the commit locally; nevertheless you can get it, without modifying your workspace, simply like this:

    git fetch
    

    After that, if ever you have current modification, or something like that, you can stash them temporary:

    git stash save "My work to be completed later"
    

    Then you can move back to your master branch:

    git checkout -f master
    

    Then, force to move the HEAD to the orphan commit you want:

    git reset --hard XYZ
    

    As alternative, in case, you prefer destroying and recreating your master branch, you can "move" to another branch, destroy the master branch and recreate it:

    git checkout -b anyOtherBranch
    git branch -D master
    git checkout -b master XYZ
    

    And eventually, push force your new master branch;

    git push --force origin master
    

提交回复
热议问题