git其他成员修改了项目怎么拉取并合并,git pull与git fetch + git merge的区别

承接上篇 B成员修改并完成了推送 github创建线上仓库关联本地文件,添加项目成员、成员完成推送

拉取命令

pull=fetch+merge

git pill origin master

git fetch origin master 抓取线上文件,把远程的内容下载到本地,并不会更改本地文件
git fetch[命令] origin[远程项目地址的别名] master[远程分支名]
git merge origin/master 将拉取的和工作区的项目合并
git merge[命令] origin[远程项目地址的别名]/master[远程分支名]

Administrator@DESKTOP-E9K0JSK MINGW64 /f/workspaces/git/huashan (master)
$ ll			
total 1
-rw-r--r-- 1 Administrator 197121 28  1月  7 17:58 huashanjianfa.txt

Administrator@DESKTOP-E9K0JSK MINGW64 /f/workspaces/git/huashan (master)
$ cat huashanjianfa.txt			#现在的本地文件代码
华山剑法,天下无敌

Administrator@DESKTOP-E9K0JSK MINGW64 /f/workspaces/git/huashan (master)
$ git fetch origin master		#重线上抓取,获得线上的代码
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/LORTER/hushan
 * branch            master     -> FETCH_HEAD
   c282f07..614eaaa  master     -> origin/master

Administrator@DESKTOP-E9K0JSK MINGW64 /f/workspaces/git/huashan (master)
$ cat huashanjianfa.txt			#再次查看本地代码依然没有变动,因为fetch只会把线上代码下载到本地,并不会更改本地工作区的文件
华山剑法,天下无敌

Administrator@DESKTOP-E9K0JSK MINGW64 /f/workspaces/git/huashan (master)
#怎么看fecth下载下来的文件
$ git checkout origin/master		#切换到origin/master
Note: switching to 'origin/master'.	

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 614eaaa test push

Administrator@DESKTOP-E9K0JSK MINGW64 /f/workspaces/git/huashan ((614eaaa...))
$ cat huashanjianfa.txt		#这样就能查看到从线上下载下来的远程master文件
华山剑法,天下无敌
狐冲剑法,天下第一,我的剑比岳不群更剑!

Administrator@DESKTOP-E9K0JSK MINGW64 /f/workspaces/git/huashan ((614eaaa...))
$ git checkout master		#切换回本地master
Previous HEAD position was 614eaaa test push
Switched to branch 'master'
Administrator@DESKTOP-E9K0JSK MINGW64 /f/workspaces/git/huashan (master)
$ cat huashanjianfa.txt		#本地master文件
华山剑法,天下无敌

Administrator@DESKTOP-E9K0JSK MINGW64 /f/workspaces/git/huashan (master)
$ git merge origin/master		#将工作区文件和远程的master文件合并
Updating c282f07..614eaaa
Fast-forward
 huashanjianfa.txt | 1 +
 1 file changed, 1 insertion(+)

Administrator@DESKTOP-E9K0JSK MINGW64 /f/workspaces/git/huashan (master)
$ cat huashanjianfa.txt		#这样,工作区的文件就改变了
华山剑法,天下无敌
狐冲剑法,天下第一,我的剑比岳不群更剑!

Administrator@DESKTOP-E9K0JSK MINGW64 /f/workspaces/git/huashan (master)
$				#拉取线上项目成功



git pull 直接就可以获取远程仓库,并更新本地工作区代码

Administrator@DESKTOP-E9K0JSK MINGW64 /f/workspaces/git/huashan (master)
$ cat huashanjianfa.txt			#git pull 前
华山剑法,天下无敌
狐冲剑法,天下第一,我的剑比岳不群更剑!

Administrator@DESKTOP-E9K0JSK MINGW64 /f/workspaces/git/huashan (master)
$ git pull origin master		#git pull  url别名	分支名
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/LORTER/hushan
 * branch            master     -> FETCH_HEAD
   614eaaa..9fa2045  master     -> origin/master
Updating 614eaaa..9fa2045
Fast-forward
 huashanjianfa.txt | 1 +
 1 file changed, 1 insertion(+)

Administrator@DESKTOP-E9K0JSK MINGW64 /f/workspaces/git/huashan (master)
$ cat huashanjianfa.txt		#git pull 后
华山剑法,天下无敌
狐冲剑法,天下第一,我的剑比岳不群更剑!
我的剑是我的剑,你的剑是真的剑!

Administrator@DESKTOP-E9K0JSK MINGW64 /f/workspaces/git/huashan (master)
$

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页