git clone和checkout有什麼區別?

本文翻譯自:What is the difference between git clone and checkout?

git clonegit checkout什麼區別?


#1樓

參考:https://stackoom.com/question/UchK/git-clone和checkout有什麼區別


#2樓

Simply git checkout have 2 uses 簡單的git checkout有2個用途

  1. Switching between existing local branches like git checkout <existing_local_branch_name> git checkout <existing_local_branch_name>類的現有本地分支之間切換
  2. 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系統窒息的所有“鎖定”(通常存在私有副本,大合併以及沒有實際控制或源代碼管理的問題;-)!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章