【问题标题】:Can someone tell me how I can get the master branch on my local repo to reflect the master branch on the remote repo?有人能告诉我如何让我的本地仓库上的主分支反映远程仓库上的主分支吗?
【发布时间】:2021-05-16 18:56:03
【问题描述】:

我不知何故将头转向了另一个地址。我可能进行了一次意外结帐并重置头部以指向其他地方。现在的问题是,现在本地 repo 的 master 分支指向几周前的随机头。我如何设置本地 repo 的头以匹配远程 repo 的 master 分支的样子。我一直在来回使用几个命令,这就是我执行 git reflog 命令时显示的内容。谢谢你,我真的很感激。

【问题讨论】:

    标签: javascript git github version-control github-cli


    【解决方案1】:

    如果当前分支是masterHEAD 指向master)将当前分支移动到与远程跟踪分支origin/master 相同的提交:

    git reset --hard origin/master
    

    如果当前分支不是master——首先结帐然后移动:

    git checkout master
    git reset --hard origin/master
    

    另一种变体:先移动非当前分支然后结帐:

    git branch --force master origin/master
    git checkout master
    

    【讨论】:

      【解决方案2】:

      您可以使用git log 显示提交列表,然后只需使用提交哈希重置HEAD

      git log
      
      /* Shows list of commits */
      
      git reset b10a4d7
      

      示例 git 日志

      * 46a3ae9 (HEAD -> main) Fix JS syntax error
      * faeed22 Do thing
      * b10a4d7 (origin/main, origin/HEAD) Linting
      * 7cb8974 Fix bugs
      

      要使用的哈希是指向origin/mainorigin/master 的哈希

      【讨论】:

        猜你喜欢
        • 2021-11-02
        • 2021-04-07
        • 1970-01-01
        • 2021-05-21
        • 1970-01-01
        • 2013-01-13
        • 1970-01-01
        • 2012-01-05
        • 2020-01-05
        相关资源
        最近更新 更多