Git pull 和 Git fick 之间有什么区别?


当前回答

git pull 命令其实是 Git 抓取的快捷键, 后面是 git 合并或 git 重设命令, 取决于您的配置 。 您可以配置您的 Git 仓库, 这样 git pull 是一个抓取, 后面是重置 。

其他回答

回报 :

谈到上述答案中的拉动和取回,我想分享一个有趣的把戏,

git Pull -- rebase

以上命令是我生命中最有用的命令 挽救了很多时间

在将您的新承诺推进到服务器之前, 请尝试此命令, 它会自动同步最新的服务器更改( 加上一个抓取 + 合并) , 并将您的承诺放在 Git 日志的顶部 。 无需担心手动拉动/ 合并 。

详情见:http://gitolite.com/git-pull-rebase

git pull 命令其实是 Git 抓取的快捷键, 后面是 git 合并或 git 重设命令, 取决于您的配置 。 您可以配置您的 Git 仓库, 这样 git pull 是一个抓取, 后面是重置 。

简单简便的答案是,Git拉动只是git抓取,然后是git合并。

必须指出, git pull 将自动合并, 不管你喜不喜欢。 当然, 这可能导致合并冲突 。 假设您的远程是源头, 您的分支是主人 。 如果您在拉动前跳过 diff 源/ master , 您应该知道潜在的合并冲突, 并据此为您所在的分支做好准备 。

除了拉拉之外,一些工作流程还涉及重设基准,例如这一项,我从相关条款中转述如下:

git pull origin master
git checkout foo-branch
git rebase master
git push origin foo-branch

如果你发现自己处于这种情况,你可能会被诱惑去拉拉 - rebase。除非你真的知道自己在做什么,否则我建议你不要这样做。这个警告是从git-pull的网页上发出的,版本2.3.5:

这是一个潜在危险的操作模式。 它重写历史, 当您已经发布历史时, 历史并不是好兆头。 除非您仔细阅读了 git- rebase(1) , 否则不要使用此选项 。

我也为此挣扎过。事实上,我来到这里时,用谷歌搜索了完全相同的问题。阅读了所有这些答案,终于在我脑海中画出了一张图片,我决定试着从下面看2个储存库和1个沙箱的状况,以及一段时间以来在看它们的版本时所采取的行动。这就是我所想出来的。如果我在任何地方搞砸了,请纠正我。

三个邮箱有一个接听器:

---------------------     -----------------------     -----------------------
- Remote Repo       -     - Remote Repo         -     - Remote Repo         -
-                   -     - gets pushed         -     -                     -
- @ R01             -     - @ R02               -     - @ R02               -
---------------------     -----------------------     -----------------------

---------------------     -----------------------     -----------------------
- Local Repo        -     - Local Repo          -     - Local Repo          -
- pull              -     -                     -     - fetch               -
- @ R01             -     - @ R01               -     - @ R02               -
---------------------     -----------------------     -----------------------

---------------------     -----------------------     -----------------------
- Local Sandbox     -     - Local Sandbox       -     - Local Sandbox       -
- Checkout          -     - new work done       -     -                     -
- @ R01             -     - @ R01+              -     - @R01+               -
---------------------     -----------------------     -----------------------

三号邮局拉一拉一拉

---------------------     -----------------------     -----------------------
- Remote Repo       -     - Remote Repo         -     - Remote Repo         -
-                   -     - gets pushed         -     -                     -
- @ R01             -     - @ R02               -     - @ R02               -
---------------------     -----------------------     -----------------------

---------------------     -----------------------     -----------------------
- Local Repo        -     - Local Repo          -     - Local Repo          -
- pull              -     -                     -     - pull                -
- @ R01             -     - @ R01               -     - @ R02               -
---------------------     -----------------------     -----------------------

---------------------     -----------------------     -----------------------
- Local Sandbox     -     - Local Sandbox       -     - Local Sandbox       -
- Checkout          -     - new work done       -     - merged with R02     -
- @ R01             -     - @ R01+              -     - @R02+               -
---------------------     -----------------------     -----------------------

这帮助我理解了为什么买东西很重要。

我想用视觉来描述这些事情。也许其他开发商也想看,所以我还要补充一下。我不完全确定这一切是否都正确,所以如果你发现任何错误,请评论。

                                         LOCAL SYSTEM
                  . =====================================================    
================= . =================  ===================  =============
REMOTE REPOSITORY . REMOTE REPOSITORY  LOCAL REPOSITORY     WORKING COPY
(ORIGIN)          . (CACHED)           
for example,      . mirror of the      
a github repo.    . remote repo
Can also be       .
multiple repo's   .
                  .
                  .
FETCH  *------------------>*
Your local cache of the remote is updated with the origin (or multiple
external sources, that is git's distributed nature)
                  .
PULL   *-------------------------------------------------------->*
changes are merged directly into your local copy. when conflicts occur, 
you are asked for decisions.
                  .
COMMIT            .                             *<---------------*
When coming from, for example, subversion, you might think that a commit
will update the origin. In git, a commit is only done to your local repo.
                  .
PUSH   *<---------------------------------------*
Synchronizes your changes back into the origin.

拥有远程镜像的一些主要优点是:

性能(通过所有承诺和信息,而不试图通过网络挤压它) 有关您本地回购状态的反馈(例如,我使用阿特拉斯西安的源树树枝,这给了我一个灯泡,显示我是否比来源提前或落后。这个信息可以用GIT FETCH来更新 ) 。