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分支

相关推荐
Lx3523 小时前
Hadoop数据处理优化:减少Shuffle阶段的性能损耗
大数据·hadoop
Elasticsearch6 小时前
平衡尺度:利用权重使倒数排序融合 (RRF) 更加智能
elasticsearch
武子康7 小时前
大数据-99 Spark Streaming 数据源全面总结:原理、应用 文件流、Socket、RDD队列流
大数据·后端·spark
阿里云大数据AI技术1 天前
大数据公有云市场第一,阿里云占比47%!
大数据
权咚1 天前
阿权的开发经验小集
git·ios·xcode
Lx3521 天前
Hadoop容错机制深度解析:保障作业稳定运行
大数据·hadoop
muyun28001 天前
Docker 下部署 Elasticsearch 8 并集成 Kibana 和 IK 分词器
elasticsearch·docker·容器
T06205141 天前
工具变量-5G试点城市DID数据(2014-2025年
大数据
向往鹰的翱翔1 天前
BKY莱德因:5大黑科技逆转时光
大数据·人工智能·科技·生活·健康医疗
鸿乃江边鸟1 天前
向量化和列式存储
大数据·sql·向量化