两者之间有什么区别?git pullgit fetch?


当前回答

简简单简的答案是:git pull简单git fetch和继 继 继 继 继 继git merge.

必须指出,git pull不管你喜不喜欢自动合并。这当然可能导致合并冲突。让我们假设你的远程是origin并且你的分支是master。如果您git diff origin/master在拉车之前,你应该对潜在的合并冲突有某种了解,并且可以据此为你的当地部门做好准备。

除了拉和推,一些工作流程涉及git rebase,例如这一条,我从相关条款中转述如下:

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

如果你发现自己处于这种情况, 你可能会被诱惑git pull --rebase除非您真的知道自己在做什么 否则我建议不要这么做man页面git-pull版本, 版本2.3.5:

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

其他回答

git-pull - Fetch from and merge with another repository or a local branch
SYNOPSIS

git pull   …
DESCRIPTION

Runs git-fetch with the given parameters, and calls git-merge to merge the 
retrieved head(s) into the current branch. With --rebase, calls git-rebase 
instead of git-merge.

Note that you can use . (current directory) as the <repository> to pull 
from the local repository — this is useful when merging local branches 
into the current branch.

Also note that options meant for git-pull itself and underlying git-merge 
must be given before the options meant for git-fetch.

如果你想要合并历史,你会拉拉, 你会拉拉,你会拉拉拉,如果你只是"想要的cotz" ,因为有人一直在标记 一些文章在这里。

您可以从远程仓库获取, 查看差异, 然后拉动或合并 。

这是被称作远程仓库的示例origin和支派,和支派,master跟踪远程分支origin/master:

git checkout master                                                  
git fetch                                        
git diff origin/master
git rebase origin master

git 拉

它使用单一命令执行两个函数。

它会获取对远程分支的所有修改, 然后将这些修改合并到您的本地分支中。 您也可以通过 -- rebase 来修改拉动行为。 合并和重基准的区别可以读取在这里

git 获取 git 获取

Git 抓取仅能完成 Git pull 的一半工作。 它只是将远程更改带入您的本地回购, 但没有将其应用到分支中 。 您必须明确应用这些更改 。 这可以做如下操作 :

git fetch
git rebase origin/master
  • git pull获取承诺后尝试自动合并 。上下文敏感,因此所有被拉动的承诺都将合并为您目前活跃的分支。git pull自动合并承诺未经审查,而不先审查。。如果你不仔细管理自己的分支,你可能会遇到频繁的冲突。

  • git fetch收集当前分支中不存在的目标分支的任何承诺,并将其存储在本地仓库中然而,它不会与您当前分支合并。如果您需要不断更新您的仓库,但正在研究一些更新文件时可能中断的文件。要将承诺整合到当前分支中,您必须使用git merge之后。