Git Fetch vs Pull:Git Fetch和Git Pull命令之间有什么区别?

Git pull and fetch are two commands that are regularly used by Git users. Let’s see the difference between both commands.

Git pullfetch是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.

那就是fetchpull入的地方。

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

翻译自: https://www.freecodecamp.org/news/git-fetch-vs-pull/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值