git fetch

当协同开发的时候,你团队中有成员将自己的修改提交到了服务器,你应该要将修改同步到本地,如何操作了?

git fetch

hui.qian@HUIQIANPC /e/appium (doctorq)
$ git fetch origin
remote: Counting objects: 22, done.
remote: Compressing objects: 100% (22/22), done.
remote: Total 22 (delta 9), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (22/22), done.
From https://github.com/testerhome/appium
   a1f6cc7..37d244c  master     -> origin/master

hui.qian@HUIQIANPC /e/appium (doctorq)
$ git fetch
remote: Counting objects: 7, done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 7 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (7/7), done.
From https://github.com/testerhome/appium
   37d244c..6a313b2  master     -> origin/master

hui.qian@HUIQIANPC /e/appium (doctorq)
$ git diff

hui.qian@HUIQIANPC /e/appium (doctorq)
$ git merge origin/master
Updating a1f6cc7..6a313b2
Fast-forward
 docs/cn/advanced-concepts/settings.md           | 26 ++++++-------
 docs/cn/appium-setup/android-hax-emulator.cn.md |  4 +-
 docs/cn/appium-setup/android-setup.cn.md        | 38 ++++++++++++++++++
 docs/cn/appium-setup/android-setup.md           | 51 -------------------------
 docs/cn/appium-setup/parallel_tests.cn.md       | 30 +++++++++++++++
 docs/cn/appium-setup/parallel_tests.md          | 30 ---------------
 6 files changed, 84 insertions(+), 95 deletions(-)
 create mode 100644 docs/cn/appium-setup/android-setup.cn.md
 delete mode 100644 docs/cn/appium-setup/android-setup.md
 create mode 100644 docs/cn/appium-setup/parallel_tests.cn.md
 delete mode 100644 docs/cn/appium-setup/parallel_tests.md

首先通过git fetch或者git fetch <远程分支名>更新到本地的origin/master中,然后通过git merge <本地分支>,来合并更新到我们的开发分支中,我们一般使用master来同步同origin/master的,这种方式是比较安全的。

git pull

我们知道git pull也有将远程仓库的更新同步到本地,尤其是从svn转过来的同学,可能都喜欢pull命令,但是pull命令后面的过程其实是git fetch和git merge两个操作。所以说是类似的操作,但是为什么会有2个不同的方式。git fetch的好处在于,你可以在同步的时候可以事先了解一下更新的内容来确定是否同步。通过如下命令查看区别

git log -p master..origin/master

你可能感兴趣的:(git)