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


当前回答

所有分支都存放在.git/refs

所有地方分支机构都存放在.git/refs/heads

所有远程分支都存放在.git/refs/remotes

缩略git fetch命令下载 承诺, 文件, 和 refs 从远程仓库下载到您的本地 repo 。 抓取是您想要看到其他人正在做的工作时要做的事情 。

所以当你做git fetch全部文件、 承诺和 refs 都下载在

此目录.git/refs/remotes

您可以切换到这些分支以查看变化 。

另外,如果你愿意,你可以把它们合并起来。

git pull只需下载这些更改, 并将其合并到当前分支 。

示例示例示例示例

如果您想看远程分支的工作dev/jd/feature/auth,你只需要做

git fetch origin dev/jd/feature/auth

看到变化或工作进展做,

git checkout dev/jd/feature/auth

但如果您也想要获取它们并将其合并到当前分支,

git pull origin dev/jd/feature/auth

如果有的话git fetch origin branch_name,它将获取分支,现在您可以切换到您想要的分支,并看到变化。您的本地主子或其他本地分支不会受到影响。但您不会受到影响。git pull origin branch_name将获取分支, 并合并到当前分支 。

其他回答

最简单的说,git pull是否为 a 的git fetch续 续 agit merge.


git fetch更新您的远程跟踪分支refs/remotes/<remote>/。此操作可以随时安全运行,因为它不会改变您在refs/heads.

git pull本地分支提供其远程版本的最新信息,同时更新其他远程跟踪分支。

调自 Git 文档git pull:

git pull运行中git fetch使用给定参数,然后取决于配置选项或命令行的旗帜,将调用其中之一git rebasegit merge以便各处之间互相调和。


有必要记住,在任何特定机器的Git存储库工作时,存储库载有来自所有远程的所有分支的复制件,以及每个地方分支的复制件,你已经做了一些工作。

你可以看到这个使用git branch -a显示您所在的分支机构,包括master和所有遥控器的分支。

master
feature/my-feature-branch
remotes/origin/master
remotes/origin/my-feature-branch
remotes/another-remote-machine/master
remotes/another-remote-machine/my-feature-branch

上面我已指出 遥控遥控器的存在origin以另一个名称返回和另一个远程another-remote-machine.

注意 您不必在所有仓库中拥有每个分支的复制件 。 (remotes 和 local.) 它取决于您通过运行同步 。git pull, git push, git fetch,来自不同的机器 / 仓库 所涉及的。

git pull = git fetch + git merge 
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" ,因为有人一直在标记 一些文章在这里。

我们简单地说:

git pull == git fetch + git merge

如果你逃跑git pull中,您不需要将数据合并到本地数据。如果运行git fetch这意味着你必须跑git merge获取本地机器的最新代码。 否则, 本地机器代码不会在不合并的情况下被更改 。

所以在 Git Gui 中, 当您获取时, 您必须合并数据 。 获取本身不会在本地修改代码 。 您可以检查当您通过一次获取并查看来更新代码时, 是否更新了代码; 代码不会改变 。 然后您将合并... 您将会看到修改后的代码 。

git pull = = (获取 Git + git 合并)

git refick 不改变本地分支 。

如果您已经拥有一个本地仓库, 并且为所要的工程设置了远程设置, 您可以使用 git 抓取, 来抓取所有现有的远程的分支和标记 。... Fetch 不改变本地分支 。 因此您需要将远程分支与本地分支合并, 以纳入新抓取的更改 。发自 Github