更简单地解释 GIT checkout 命令的路径
在 checkout 命令的 git 文档 中找到以下文本:
...如果没有给出路径, git checkout 也会将 HEAD 更新为 将指定分支设置为 当前分支....
任何人都可以对这意味着什么给出更简单的解释吗?如果这看起来很简单,我很抱歉,并且通读该页,我似乎无法弄清楚它的确切含义。抱歉,如果这看起来很基本......
特别是我对结账如何更新 HEAD 感到困惑。我通常设想签出会影响工作目录——这是 git 独有的功能吗?因为您正在更新存储库的本地副本以便稍后使用它?
In the git documentation for the checkout command the following text is found:
...If no paths are given,
git checkout will also update HEAD to
set the specified branch as the
current branch....
Can anyone give a simpler explanation of what this means? I'm sorry if it seems simple, and reading through that page, I can't seem to come up with what it means exactly. Sorry if this seems basic..
In particular I am confused on how checkout is updating HEAD. I usually envision checkout affecting the working directory -- is this an ability unique to git in that you are updating your local copy of the repository for the purposes of working with it later?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
版本 A:(仅指定分支)
获取该<分支>的所有文件并将 HEAD(指向“我现在在哪里”的指针)放置在指定的分支处。
版本 B:(仅指定路径)
获取的最新版本并留下 HEAD 独自一人。
Version A: (specifying only the branch)
Gets all files for that <branch> and places HEAD (a pointer to "where am I now") at the branch specified.
Version B: (specifying a path only)
Gets the latest version of <file> and leaves HEAD alone.
HEAD
是指向签出工作副本的提交的指针。因此,如果您签出分支(或提交或标记),则HEAD
将设置为该提交。这些信息存储在文本文件
.git/HEAD
中,您可以简单地查看其内容:HEAD
is a pointer to the commit your working copy was checked out from. so if you checkout a branch (or commit or tag) thenHEAD
is set to that commit.this information is stored in the textfile
.git/HEAD
, you can simply look at its content:这意味着 git checkoutbranchname 将从
例子:
It means that
git checkout branchname
willHEAD
to the tip of that branch, so that you are now "on" it.Example:
如果您处于 DETACHED HEAD 模式(请参阅这个问题),您可以轻松地将 HEAD 重置到主分支:
这里的 '
git checkout
' 会将 HEAD 重置到master
分支的尖端。(更多内容请参阅“可视化 Git 参考”)
它还将更新索引和工作目录。
所以这不仅仅是重置指针“
HEAD
”。If you are in a DETACHED HEAD mode (see this question), you could easily reset HEAD to the master branch:
Here a '
git checkout
' would reset HEAD to the tip ofmaster
branch.(More in "A Visual Git Reference")
It will also update both the index and the working directory.
So it is not just about resetting the pointer '
HEAD
'.对于 Git 2.23+(2019 年 8 月),请使用
git switch
而不是令人困惑的git checkout
,加上git Restore
(仅适用于文件)这会将 HEAD 切换回
master
。您仍然可以使用
git switch --detach
直接引用提交(分离的 HEAD)。不再需要签出(同时处理分支和文件)。
With Git 2.23+ (August 2019), use
git switch
instead of the confusinggit checkout
, coupled withgit restore
(for files only)That would switch HEAD back to
master
.You can still reference a commit directly (detached HEAD) with
git switch --detach <acommit>
.No more checkout (which deals both with branches and files).