目录:
1. git合并分支代码
2. git fetch 、git pull、git merge原理[引申]
一. git合并分支代码
举例:本地分支master, 远程目标分支:dev
合并:将远程origin仓库的dev分支合并到本地的master分支
git合并分支代码一般有如下两种方式
第一种方式:
git fetch origin dev // fetch到远程仓库目标分支的最新commit记录到 ./git/FETCH_HEAD文件中
git checkout master // 切换到要合并的分支
git merge FETCH_HEAD // 将目标分支最新的commit记录合并到当前分支
二. git fetch 、git pull、git merge原理
2.1 相关基础知识
首先介绍下git相关的一些基础知识:git remote,git merge 、远程repo, branch 、 commit-id
2.2 git fetch
四种基本用法:
1. git fetch →→ 这将更新git remote 中所有的远程repo 所包含分支的最新commit-id, 将其记录到.git/FETCH_HEAD文件中
2. git fetch remote_repo →→ 这将更新名称为remote_repo 的远程repo上的所有branch的最新commit-id,将其记录。
3. git fetch remote_repo remote_branch_name →→ 这将这将更新名称为remote_repo 的远程repo上的分支: remote_branch_name
4. git fetch remote_repo remote_branch_name:local_branch_name →→ 这将这将更新名称为remote_repo 的远程repo上的分支: remote_branch_name ,并在本地创建local_branch_name 本地分支保存远端分支的所有数据。
FETCH_HEAD: 是一个版本链接,记录在本地的一个文件中,指向着目前已经从远程仓库取下来的分支的末端版本。
2.3 git pull
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/219357.html原文链接:https://javaforall.net
