Git pull
and fetch
are two commands that are regularly used by Git users. Let’s see the difference between both commands.
Git pull
和fetch
是Git用户经常使用的两个命令。 让我们看看两个命令之间的区别。
For the sake of context, it’s worth remembering that we’re probably working in a clone repo. What’s a clone? It's simply a duplicate of another repository. It is basically getting your own copy of someone else’s source code.
出于上下文考虑,值得记住的是,我们可能正在克隆克隆中。 什么是克隆? 它只是另一个存储库的副本。 它基本上是在获取您自己的他人源代码副本。
That said, to keep your clone updated with whatever changes may have been applied to the original, you’ll need to bring those to your clone.
就是说,要使克隆更新时可以对原始副本进行任何更改,则需要将其带入克隆。
That’s where fetch
and pull
come in.
那就是fetch
和pull
入的地方。
git fetch
is the command that tells your local git to retrieve the latest meta-data info from the original (yet doesn’t do any file transferring. It’s more like just checking to see if there are any changes available).
git fetch
是告诉您的本地git从原始数据库中检索最新元数据信息的命令(但尚未进行任何文件传输。它更像是检查是否有可用更改)。
git pull
on the other hand does that AND brings (copy) those changes from the remote repository.
另一方面, git pull
做到并从远程存储库中带来(复制)那些更改。
For example:
例如:
git pull origin ankur bugfix
The takeaway is to keep in mind that there generally are at least three copies of a project on your workstation.
要记住的一点是,您的工作站上通常至少有一个项目的三个副本。
- One copy is your own repository with your own commit history (the already saved one, so to say). 一个副本是您自己的存储库,具有自己的提交历史记录(可以说已经保存了一个)。
- The second copy is your working copy where you are editing and building (not committed yet to your repo). 第二个副本是您正在编辑和构建的工作副本(尚未提交到您的存储库)。
- The third copy is your local “cached” copy of a remote repository (probably the original from where you cloned yours). 第三个副本是远程存储库的本地“缓存”副本(可能是您从中克隆副本的原始副本)。
You can use git fetch
to know the changes done in the remote repo/branch since your last pull. This is useful to allow for checking before doing an actual pull, which could change files in your current branch and working copy (and potentially lose your changes, etc).
您可以使用git fetch
知道自上次提取以来在远程存储库/分支中所做的更改。 这有助于在进行实际提取之前进行检查,这可能会更改当前分支和工作副本中的文件(并可能丢失所做的更改等)。
git fetch
git diff ...origin