git checkout真的意味着什么? [英] What do git checkouts really mean?

查看:410
本文介绍了git checkout真的意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在git中 checkout 是什么?



我知道,一旦你做了 checkout 到一个特定的分支, HEAD 指向该分支。但它的真正含义是什么?这是否意味着我可以在那个分支上工作?如果是,那么,如果没有检出分支,我无法处理它?<​​b>

另外,远程结帐是什么意思?它是如何有用的?

解决方案

正如你所说, HEAD 是一个标签注明您在提交树中的位置。当你从一个提交移动到另一个提交时,它随你移动。 git checkout< commit> 是在提交树中移动的基本机制,移动焦点( HEAD )到指定的提交。

提交可以通过多种方式指定,提交哈希,分支名称,标记名称,相对语法( HEAD ^ HEAD〜1 等)等等。将结账视为改变分支通常是有用的,并且从这个角度看有一些选项可以工作,但它们都引用了提交。



要签出提交除了移动 HEAD 周围外,一些方面的影响。




  • 工作目录更新为签出的提交的状态。

  • 如果指定了分支名称,checkout会使该分支活动。活动分支将随着所添加的任何新提交一起移动。


    • -b 选项一个新分支将根据当前的提交创建,然后创建使用 - track 选项可以使已签出的分支知道远程分支

    • - orphan 选项一起创建一个新分支(如 -b ),但会不是基于任何现有的提交。




您可以在 git checkout手册页中阅读这些内容,所有这些内容都围绕着从一个提交到另一个提交 - 除了移动 HEAD 之外,移动的效果也不尽相同。


What are checkouts in git?

I know once you do checkout to a particular branch, the HEAD points to that branch. But what does it really mean? Does it mean I can then work on that branch? If yes, then, without checking out a branch, I am not able to work on it?

Also, what does remote checkout mean? How is it useful?

解决方案

As you noted, HEAD is a label noting where you are in the commit tree. It moves with you when you move from one commit to another. git checkout <commit> is the basic mechanism for moving around in the commit tree, moving your focus (HEAD) to the specified commit.

The commit can be specified by any of a number of ways, commit hash, branch name, tag name, the relative syntax (HEAD^, HEAD~1, etc.) and so on. It is often useful to consider a checkout to be changing branches, and there are some options that work from that perspective, but they all reference commits.

To checkout a commit has some side affects other than moving HEAD around.

  • The working directory is updated to the state of the checked out commit.
  • if a branch name is specified, checkout makes that branch active. The active branch will move along with any new commits that are added.
    • with the -b option a new branch will be created based on the current commit and then made active.
    • with the --track option the checked out branch can be made aware of a remote branch
    • with the --orphan option a new branch is created (like with -b) but will not be based on any existing commit.

There are a few more options, which you can read about in the git checkout man-page, all of which revolve around moving from one commit to another -- just varying in what effect that move has in addition to moving HEAD.

这篇关于git checkout真的意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆