当前回答
实际上 Git 保有一份您自己的代码副本和远程仓库 。
命令git fetch
通过从远程仓库获取数据来更新您的本地副本。 我们需要这个数据的原因是, 其他人可能对代码做了一些修改, 您想要不断更新自己 。
命令git pull
将远程仓库的更改引入到您保存自己的代码的位置。通常,git pull
这样做的方式是先做一个“ 直接获取” , 将远程仓库的本地副本更新, 然后将修改合并到您自己的代码存储处, 并有可能将您的工作副本合并到您自己的代码存储处 。
其他回答
我们简单地说:
git pull == git fetch + git merge
如果你逃跑git pull
中,您不需要将数据合并到本地数据。如果运行git fetch
这意味着你必须跑git merge
获取本地机器的最新代码。 否则, 本地机器代码不会在不合并的情况下被更改 。
所以在 Git Gui 中, 当您获取时, 您必须合并数据 。 获取本身不会在本地修改代码 。 您可以检查当您通过一次获取并查看来更新代码时, 是否更新了代码; 代码不会改变 。 然后您将合并... 您将会看到修改后的代码 。
两者有什么区别?
git pull
和git fetch
?
要理解这一点,你首先需要明白,你所在的本地数据库不仅维护着您的本地存储库,而且还维护着远程存储库的本地副本。
git fetch
将远程仓库的本地副本更新到最新 。 例如, 如果您的远程仓库是 GitHub , 您可能想要将远程仓库中所做的任何更改移到您的本地副本 远程仓库。 这将允许您执行比较或合并等操作 。
git pull
另一方面,会将远程仓库的更改降低到您保存自己的代码的位置。 通常,git pull
会做一个git fetch
首先将远程存储库的本地副本更新, 然后它将把修改合并到您自己的代码存储库中, 并可能合并到您的工作副本中 。
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" ,因为有人一直在标记 一些文章在这里。
我想用视觉来描述这些事情。也许其他开发商也想看,所以我还要补充一下。我不完全确定这一切是否都正确,所以如果你发现任何错误,请评论。
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 Fitch 来更新 ) 。
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式
- git pull -rebase和git pull -ff-only之间的区别