git 中的 pull 和 clone 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3620633/
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 pull and clone in git?
提问by cmcculloh
What is the difference between doing (after mkdir repo
and cd repo
):
做(之后mkdir repo
和cd repo
)有什么区别:
git init
git remote add origin git://github.com/cmcculloh/repo.git
git fetch --all
git pull origin master
and
和
git clone git://github.com/cmcculloh/repo.git
I mean, obviously one is shorter, but other than that are they basically doing the same thing?
我的意思是,显然一个更短,但除此之外,他们基本上做同样的事情吗?
采纳答案by meagar
They're basically the same, except clone will setup additional remote tracking branches, not just master. Check out the man page:
它们基本相同,除了 clone 会设置额外的远程跟踪分支,而不仅仅是 master。查看手册页:
Clones a repository into a newly created directory, creates remote-tracking branches for each branch in the cloned repository (visible using git branch -r), and creates and checks out an initial branch that is forked from the cloned repository's currently active branch.
将存储库克隆到新创建的目录中,为克隆存储库中的每个分支创建远程跟踪分支(使用 git branch -r 可见),并创建并检出从克隆存储库当前活动分支分叉的初始分支。
回答by ebneter
git clone
is how you get a local copy of an existing repository to work on. It's usually only used once for a given repository, unless you want to have multiple working copies of it around. (Or want to get a clean copy after messing up your local one...)
git clone
是如何获取现有存储库的本地副本以进行处理。对于给定的存储库,它通常只使用一次,除非您想拥有它的多个工作副本。(或者想在弄乱本地副本后获得一份干净的副本......)
git pull
(or git fetch
+ git merge
) is how you updatethat local copy with new commits from the remote repository. If you are collaborating with others, it is a command that you will run frequently.
git pull
(或git fetch
+ git merge
)是您使用来自远程存储库的新提交更新本地副本的方式。如果您正在与他人协作,这是您将经常运行的命令。
As your first example shows, it is possible to emulate git clone
with an assortment of other git commands, but it's not really the case that git pull
is doing "basically the same thing" as git clone
(or vice-versa).
作为你的第一个例子,有可能效仿git clone
其他Git命令的分类,但它不是真的,此案git pull
正在做“基本上是一回事”为git clone
(反之亦然)。
回答by Jyoti Prakash
In laymen language we can say:
用外行的语言我们可以说:
- Clone: Get a working copy of the remote repository.
- Pull: I am working on this, please get me the new changes that may be updated by others.
- 克隆:获取远程存储库的工作副本。
- Pull:我正在研究这个,请给我一些其他人可能会更新的新变化。
回答by Jyoti Prakash
git clone
means you are making a copy of the repository in your system.
git clone
意味着您正在系统中制作存储库的副本。
git fork
means you are copying the repository to your Github account.
git fork
意味着您正在将存储库复制到您的 Github 帐户。
git pull
means you are fetching the last modified repository.
git pull
意味着您正在获取最后修改的存储库。
git push
means you are returning the repository after modifying it.
git push
意味着您在修改它后返回存储库。
In layman's term:
通俗地说:
git clone
is downloading and git pull
is refreshing.
git clone
正在下载,git pull
正在刷新。
回答by Suman Astani
clone: copying the remote server repository to your local machine.
clone:将远程服务器存储库复制到本地计算机。
pull: get new changes other have added to your local machine.
pull:获取其他已添加到本地计算机的新更改。
This is the difference.
这就是区别。
Clone is generally used to get remote repo copy.
Clone 通常用于获取远程 repo 副本。
Pull is used to view other team mates added code, if you are working in teams.
Pull 用于查看其他团队成员添加的代码,如果您在团队中工作。
回答by Raman_1059
git cloneis used for just downloading exactly what is currently working on the remote server repository and saving it in your machine's folder where that project is placed. Mostly it is used only when we are going to upload the project for the first time. After that pull is the better option.
git clone仅用于准确下载当前在远程服务器存储库上运行的内容,并将其保存在该项目所在的机器文件夹中。大多数情况下,它仅在我们第一次上传项目时使用。在那之后拉动是更好的选择。
git pullis basically a (clone(download) + merge) operation and mostly used when you are working as teamwork. In other words, when you want the recent changes in that project, you can pull.
git pull基本上是一个(克隆(下载)+合并)操作,主要用于团队合作。换句话说,当您想要该项目的最近更改时,您可以拉取。
回答by Blue Clouds
Miss Clone: I get a fresh copy to local.
克隆小姐:我得到了一份新的本地副本。
Mr Pull: I already have it locally, I just updates it.
拉先生:我在本地已经有了,我只是更新它。
Miss Clone: I can do what you do! You are just my subset.
克隆小姐:我可以做你做的!你只是我的一个子集。
Mr Pull: Ditto!
拉先生:同上!
Miss Clone: No, you don't create. This is what I do:
克隆小姐:不,你不创造。这就是我所做的:
- Create empty bare repository
- Populate remote-tracking branches
- Run git fetch without arguments
- 创建空的裸仓库
- 填充远程跟踪分支
- 不带参数运行 git fetch
You only do #3, and then you merge, which I do not need to do(mine is fresh).
你只做#3,然后你合并,我不需要做(我的是新鲜的)。
Mr Pull: Smarty pants, no big deal, I will do a "git init" first! Then we are the same. Plus I have the extra 'merge' capability on existing repo! Which makes me the most used command in Git ;)
Mr Pull:聪明的裤子,没什么大不了的,我会先做一个“git init”!那我们就一样了。另外,我对现有的回购有额外的“合并”能力!这使我成为 Git 中最常用的命令;)
Git creators: Hold your horses Mr Pull, if --bare or --mirror is used with clone or init, your merge won't happen. It remains read-only.
Git 创建者:拉住你的马,拉先生,如果 --bare 或 --mirror 与 clone 或 init 一起使用,你的合并将不会发生。它保持只读状态。
回答by Md Abrar
git clone URL ---> Complete project or repository will be downloaded as a seperate directory. and not just the changes git pull URL ---> fetch + merge --> It will only fetch the changes that have been done and not the entire project
git clone URL ---> 完整的项目或存储库将作为单独的目录下载。而不仅仅是更改 git pull URL ---> fetch + merge --> 它只会获取已完成的更改而不是整个项目
回答by Scott
Hmm, what's missing to see the remote branch "4.2" when I pull, as I do when I clone? Something's clearly not identical.
嗯,当我拉取时看到远程分支“4.2”缺少什么,就像我克隆时一样?有些东西显然不一样。
tmp$ mkdir some_repo
tmp$ cd some_repo
some_repo$ git init
Initialized empty Git repository in /tmp/some_repo/.git/
some_repo$ git pull https://github.ourplace.net/babelfish/some_repo.git
:
From https://github.ourplace.net/babelfish/some_repo
* branch HEAD -> FETCH_HEAD
some_repo$ git branch
* master
vs
对比
tmp$ rm -rf some_repo
tmp$ git clone https://github.ourplace.net/babelfish/some_repo.git
Cloning into 'some_repo'...
:
Checking connectivity... done.
tmp$ cd some_repo
some_repo$ git branch
* 4.2
回答by simopr
While the git fetch
command will fetch down all the changes on the server that you don't have yet, it will not modify your working directory at all. It will simply get the data for you and let you merge it yourself. However, there is a command called git pull
which is essentially a git fetch
immediately followed by a git merge
in most cases.
虽然该git fetch
命令将获取服务器上您还没有的所有更改,但它根本不会修改您的工作目录。它只会为您获取数据并让您自己合并。然而,在大多数情况下,有一个被调用的命令git pull
本质上是git fetch
紧跟在 a 之后git merge
。
Read more: https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches#Pulling
阅读更多:https: //git-scm.com/book/en/v2/Git-Branching-Remote-Branches#Pulling