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


当前回答

Git使用两个命令从远程到本地获取最新版本的分支 :

git 获取 : Git 会从远程获取最新版本到本地版本, 但不会自动合并 。 git 获取来源母版 master git log -p master. 来源/ master git 合并来源/ master 。 上面的命令意味着从远程下载主分支的最新版本, 从原始到来源母分支。 然后比较本地主分支和源母母分支。 最后, 合并 。 git pull : Git 会从远程获取最新版本并合并到本地 。 git pull 源母版 。 上面的命令相当于 git 获取和 git 合并 。 在实践中, git 获取可能更安全一些, 因为合并前我们可以看到这些修改并决定是否合并 。

其他回答

我也为此挣扎过。事实上,我来到这里时,用谷歌搜索了完全相同的问题。阅读了所有这些答案,终于在我脑海中画出了一张图片,我决定试着从下面看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+               -
---------------------     -----------------------     -----------------------

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

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

这是被称作起源的远程存储库和名为“跟踪远程分支来源/主管”的分支的分支的一个例子:

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

以下是Oliver Steele的画面,

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/refs中。

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

所有远程分支都储存在.git/refs/remotes中。

git 获取命令下载承诺、 文件、 从远程仓库获取 refs 到您的本地 repo 。 获取是您想要看到其他人的工作内容时要做的事情 。

所以当您在 Git 获取所有文件、 承诺和 ref 时, 在

此目录. git/ refs/ remotes

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

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

git pull 只是下载这些修改, 并合并到当前分支 。

示例示例示例示例

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

git 获取源于 dev/jd/ feature/auth

看到变化或工作进展做,

git 检出 dev/jd/feature/auth

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

git 拉力源dev/jd/feature/auth

如果您选择了 Git 获取源代码分支_ name, 它将会获取分支, 现在您可以切换到您想要的分支, 并查看这些变化。 您的本地主子或其他本地分支不会受到影响 。 但 Git pull 源代码分支_ name 将会获取分支, 并同时合并到当前分支 。