Git 的引用规格(refspec)语法

目录

  • 引用规格语法格式
  • 常见用法
    • [强制 -f 和 + 的区别](#强制 -f 和 + 的区别)
    • [git fetch origin remote-branch:local-branch 和 git push origin local-branch:remote-branch 区别](#git fetch origin remote-branch:local-branch 和 git push origin local-branch:remote-branch 区别)

引用规格语法格式

格式如下:[+]<src>:<dst>

常见用法

bash 复制代码
# fetch
git fetch origin <remote-branch>:<local-branch>  从远程仓库 origin 的 <remote-branch> 分支拉取最新的提交,并将其创建或更新为本地的 <local-branch> 分支
git fetch origin :release 等价于 git fetch origin main:dev2 表示使用远程仓库默认分支

# pull
git pull origin <remote-branch>:<local-branch>

# push
git push origin <local-branch>:<remote-branch>   将本地仓库的 <local-branch> 分支推送到远程仓库 origin 的 <remote-branch> 分支

# 删除远程分支
git branch -d -r origin/<remote-branch>
git push origin :<remote-branch>                 删除远程仓库 origin 中的 <remote-branch> 分支

强制 -f 和 + 的区别

bash 复制代码
# +
git push origin +<local-branch>:<remote-branch>     + 表示强制的意思

git push origin +dev1216:1216                       只想强制更新一个特定的分支
git push origin -f dev1216:1216 featureA:featureA   可一次性强制更新多个分支

git fetch origin remote-branch:local-branch 和 git push origin local-branch:remote-branch 区别

git fetch origin 1216:dev1216 这条命令的作用是从名为origin的远程仓库中获取1216分支的最新代码,并将其存储为本地的dev1216远程跟踪分支。这通常用于在不立即合并的情况下,先获取远程分支的更新并进行检查或对比。
git fetch origin 1216:dev1216 这条命令目的很明确,就是从远程仓库的1216分支获取最新的更改,并将其合并到本地的 dev1216分支

相关推荐
懒惰的橘猫17 分钟前
RDD-自定义分区器案例
大数据
算法歌者33 分钟前
Visual Studio 项目 .gitignore 文件指南
git·visual studio
江边垂钓者44 分钟前
git cherry-pick和git stash命令详解
git
Lw老王要学习1 小时前
Linux架构篇、第五章git2.49.0部署与使用
linux·运维·git·云计算·it
爱学习的张哥1 小时前
专栏项目框架介绍
git·fpga开发·udp·ddr·gt收发器
富能量爆棚1 小时前
Spark缓存-cache
大数据·spark
依年南台1 小时前
Spark处理过程-案例数据清洗
大数据·hadoop
猪猪果泡酒1 小时前
Spark,RDD中的转换算子
大数据·分布式·spark
TDengine (老段)1 小时前
TDengine 做为 Spark 数据源
大数据·数据库·物联网·ajax·spark·时序数据库·tdengine
Aric_Jones4 小时前
lua入门语法,包含安装,注释,变量,循环等
java·开发语言·git·elasticsearch·junit·lua