【问题标题】:How to move the master to the current head in git?如何将master移动到git中的当前头部?
【发布时间】:2021-07-18 05:50:13
【问题描述】:

目前我的头和主人如下-

2441dc3 (HEAD) Made backend route for student attendance
2b27490 Made storage to localstorage from the classname
577bd81 (origin/master, master) Made attendace UI working though there are some errors

我现在如何让我现在的负责人成为主人?

【问题讨论】:

    标签: git git-commit


    【解决方案1】:

    您可以对 master 分支进行硬重置,或重置为 master 最新的 SHA-1 哈希:

    # from your current branch
    git reset --hard origin/master
    git reset --hard 577bd81
    

    【讨论】:

      【解决方案2】:

      你在当前的HEAD 上重新创建master 然后检查一下:

      git branch -f master
      git checkout master
      

      这给了你

      2441dc3 (HEAD -> master) Made backend route for student attendance
      2b27490 Made storage to localstorage from the classname
      577bd81 (origin/master) Made attendace UI working though there are some errors
      

      【讨论】:

      • 或者,在一个步骤中,git checkout -B master 或 git switch -C master。
      【解决方案3】:

      HEAD?

      HEAD 只是对当前分支上当前提交(最新)的引用。
      在任何给定时间只能有一个HEAD(不包括git worktree)。

      HEAD 的内容存储在.git/HEAD 中,它包含当前提交的 40 字节 SHA-1。


      git checkout

      git checkout <commit_id>
      git checkout -b <new branch> <commit_id>
      git checkout HEAD~X // x is the number of commits to go back
      

      这将签出指向所需提交的新分支。
      此命令将检出给定的提交。
      此时,您可以创建一个分支,并从这一点开始工作。

      # Checkout a given commit.
      # Doing so will result in a `detached HEAD` which mean that the `HEAD`
      # is not pointing to the latest so you will need to checkout branch
      # in order to be able to update the code.
      git checkout <commit-id>
      
      # Create a new branch forked to the given commit
      git checkout -b <branch name>
      

      git reset --hard &lt;commit_id&gt;

      “移动”你的 HEAD 回到所需的提交。

      # This will destroy any local modifications.
      # Don't do it if you have uncommitted work you want to keep.
      git reset --hard 0d1d7fc32
      
      # Alternatively, if there's work to keep:
      git stash
      git reset --hard 0d1d7fc32
      git stash pop
      # This saves the modifications, then reapplies that patch after resetting.
      # You could get merge conflicts if you've modified things that were
      # changed since the commit you reset to.
      
      • 注意:([自 Git 2.7][8])您也可以使用 git rebase --no-autostash。

      【讨论】:

        猜你喜欢
        • 2011-11-01
        • 2022-07-02
        • 1970-01-01
        • 2014-07-01
        • 2011-01-24
        • 2011-11-03
        • 1970-01-01
        • 2023-02-01
        相关资源
        最近更新 更多