【问题标题】:How to use 'git checkout' command如何使用“git checkout”命令
【发布时间】:2012-12-22 05:39:54
【问题描述】:

我认为下面的这个命令会检出一个远程分支名称“branch_name”并为我创建一个名为“branch_name”的本地分支。

'git checkout -b branch_name "`git remote`"/branch_name'

我的问题是

  • 尽管我已经有一个分支名称“branch_name”,我该如何运行它,我是否可以要求 git it checkout 到 branch_name 甚至(如果该分支已经存在)?

  • 当我执行 'git branch -a' 时,我没有看到分支 'remote/branch_name',我只看到一个分支 'remotes/ser-git/branch_name'。 git如何从'git remtoe'/branch_name中找到正确的删除分支?

【问题讨论】:

标签: git


【解决方案1】:

尽管我已经有一个分支名称'branch_name',我该如何运行它, 我可以要求 git it checkout 到 branch_name 甚至(如果该分支已经 存在)?

使用-B 选项而不是-b

当我执行 'git branch -a' 时,我没有看到分支 'remote/branch_name', 我只看到一个分支'remotes/ser-git/branch_name'。 git如何找到 从 'git remtoe'/branch_name 中删除正确的分支?

git 按以下顺序解析引用名称:

  1. 如果$GIT_DIR/<name> 存在,那就是你的意思(这通常只对HEADFETCH_HEADORIG_HEADMERGE_HEADCHERRY_PICK_HEAD 有用);
  2. 否则,refs/<name> 如果存在;
  3. 否则,refs/tags/<refname> 如果存在;
  4. 否则,refs/heads/<name> 如果存在;
  5. 否则,refs/remotes/<name> 如果存在;
  6. 否则,refs/remotes/<name>/HEAD 如果存在。

表示如果你有本地分支ser-git/branch_name,git会优先使用它而不是远程分支。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-05
    • 2018-01-01
    • 2016-08-29
    • 1970-01-01
    • 2021-12-06
    • 2013-09-02
    • 1970-01-01
    • 2014-11-15
    相关资源
    最近更新 更多