本文翻译自:What is the difference between git clone and checkout?
git clone
和git checkout
什么区别?
#1楼
参考:https://stackoom.com/question/UchK/git-clone和checkout有什么区别
#2楼
Simply git checkout have 2 uses 简单的git checkout有2个用途
- Switching between existing local branches like
git checkout <existing_local_branch_name>
在git checkout <existing_local_branch_name>
类的现有本地分支之间切换 - Create a new branch from current branch using flag -b. 使用标志-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 假设您在主分支处,那么git checkout -b <new_feature_branch_name>
将创建一个包含master内容的新分支并切换到新创建的分支
You can find more options at the official site 您可以在官方网站上找到更多选项
#3楼
checkout
can 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
2nd case : restore file from x rev 第二种情况 :从x rev恢复文件
git checkout rev file_to_restore
... git checkout rev file_to_restore
...
#4楼
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 clone
in SVN/CVS is checkout
. 注意:对于那些具有SVN / CVS背景且不熟悉Git的人来说,SVN / CVS中的git clone
相当于checkout
。 The same wording of different terms is often confusing. 不同术语的相同措辞通常令人困惑。
#5楼
git clone is to fetch your repositories from the remote git server. git clone是从远程git服务器获取您的存储库。
git checkout is to checkout your desired status of your repository (like branches or particular files). git checkout是检查您所需的存储库状态(如分支或特定文件)。
Eg, you are currently on master branch and you want to switch into develop branch. 例如,您当前在主分支上,并且您想要切换到开发分支。
git checkout develop_branch
Eg, you want to checkout to a particular status of a particular file 例如,您想要签出特定文件的特定状态
git checkout commit_point_A -- <filename>
Here is a good reference for you to learn Git, lets you understand much more easily. 这里有一个很好的参考 ,你可以学习Git,让你更容易理解。
#6楼
One thing to notice is the lack of any "Copyout" within git. 有一点需要注意的是git中缺少任何“Copyout”。 That's because you already have a full copy in your local repo - your local repo being a clone
of your chosen upstream repo. 那是因为您已在本地仓库中拥有完整副本 - 您的本地仓库是您所选上游仓库的clone
。 So you have effectively a personal checkout
of everything , without putting some 'lock' on those files in the reference repo. 因此,您可以有效地对所有内容进行个人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. Git提供SHA1哈希值作为验证文件/目录树/ commit / repo的副本与能够在信任层次结构中将事物声明为“主”的人所使用的完全相同的机制。 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 ;-) ! 这避免了导致大多数SCM系统窒息的所有“锁定”(通常存在私有副本,大合并以及没有实际控制或源代码管理的问题;-)!