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
What is the difference between git clone and checkout?
提问by Praveen Sripati
What is the difference between git clone
and 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 clone
in 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 clone
of your chosen upstream repo. So you have effectively a personal checkout
of 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 个用途
- Switching between existing local branches like
git checkout <existing_local_branch_name>
- 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
- 在现有的本地分支之间切换,例如
git checkout <existing_local_branch_name>
- 使用标志 -b 从当前分支创建一个新分支。假设您在 master 分支,那么
git checkout -b <new_feature_branch_name>
将使用 master 的内容创建一个新分支并切换到新创建的分支
You can find more options at the official site
您可以在官方网站上找到更多选项
回答by Goms
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
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
...