git clone 和 checkout 有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7298598/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 11:46:13  来源:igfitidea点击:

What is the difference between git clone and checkout?

gitcommand

提问by Praveen Sripati

What is the difference between git cloneand git checkout?

git clone和 和有git checkout什么区别?

回答by August Lilleaas

The man page for checkout: http://git-scm.com/docs/git-checkout

结帐手册页:http: //git-scm.com/docs/git-checkout

The man page for clone: http://git-scm.com/docs/git-clone

克隆的手册页:http: //git-scm.com/docs/git-clone

To sum it up, clone is for fetching repositories you don't have, checkout is for switching between branches in a repository you already have.

总而言之,clone 用于获取您没有的存储库,checkout 用于在您已有的存储库中的分支之间切换。

Note: for those who have a SVN/CVS background and new to Git, the equivalent of git clonein SVN/CVS is checkout. The same wording of different terms is often confusing.

注意:对于那些有 SVN/CVS 背景并且刚接触 Git 的人来说,git clone在 SVN/CVS 中的等价物是checkout. 不同术语的相同措辞常常令人困惑。

回答by Kit Ho

git cloneis to fetch your repositories from the remote git server.

git clone用于从远程 git 服务器获取您的存储库。

git checkoutis to checkout your desired status of your repository (like branches or particular files).

git checkout用于检出您想要的存储库状态(如分支或特定文件)。

E.g., you are currently on master branch and you want to switch into develop branch.

例如,您当前在 master 分支上,并且想要切换到 develop 分支。

git checkout develop_branch

E.g., you want to checkout to a particular status of a particular file

例如,您想检出特定文件的特定状态

git checkout commit_point_A -- <filename>

Here is a good referencefor you to learn Git, lets you understand much more easily.

这里是你学习Git的好参考,让你更容易理解。

回答by Philip Oakley

One thing to notice is the lack of any "Copyout" within git. That's because you already have a fullcopy in your local repo - your local repo being a cloneof your chosen upstream repo. So you have effectively a personal checkoutof everything, without putting some 'lock' on those files in the reference repo.

需要注意的一件事是 git 中缺少任何“复制”。那是因为您的本地存储库中已经有一个完整副本 - 您的本地存储库是clone您选择的上游存储库的一个。所以,你必须有效个人checkout一切,而不对这些文件的一些“锁”在基准回购。

Git provides the SHA1 hash values as the mechanism for verifying that the copy you have of a file / directory tree / commit / repo is exactly the same as that used by whoever is able to declare things as "Master" within the hierarchy of trust. This avoids all those 'locks' that cause most SCM systems to choke (with the usual problems of private copies, big merges, and no real control or management of source code ;-) !

Git 提供 SHA1 哈希值作为验证您拥有的文件/目录树/提交/存储库副本与能够在信任层次结构中将事物声明为“主”的任何人使用的副本完全相同的机制。这避免了所有导致大多数 SCM 系统窒息的“锁定”(通常存在私有副本、大合并以及对源代码没有真正控制或管理的问题;-)!

回答by Khader M A

Simply git checkout have 2 uses

简单的 git checkout 有 2 个用途

  1. Switching between existing local branches like git checkout <existing_local_branch_name>
  2. Create a new branch from current branch using flag -b. Suppose if you are at master branch then git checkout -b <new_feature_branch_name>will create a new branch with the contents of master and switch to newly created branch
  1. 在现有的本地分支之间切换,例如 git checkout <existing_local_branch_name>
  2. 使用标志 -b 从当前分支创建一个新分支。假设您在 master 分支,那么git checkout -b <new_feature_branch_name>将使用 master 的内容创建一个新分支并切换到新创建的分支

You can find more options at the official site

您可以在官方网站上找到更多选项

回答by Goms

checkoutcan be use for many case :

checkout可用于许多情况:

1st case: switch between branch in local repository For instance : git checkout exists_branch_to_switch

第一种情况:在本地存储库中的分支之间切换例如: git checkout exists_branch_to_switch

You can also create new branch and switch out in throught this case with -b

您还可以创建新分支并在这种情况下切换 -b

git checkout -b new_branch_to_switch

git checkout -b new_branch_to_switch

2nd case: restore file from x rev

第二种情况:从 x rev 恢复文件

git checkout rev file_to_restore ...

git checkout rev file_to_restore ...