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

相关推荐
songyuc14 小时前
【Git】请帮忙解释一下“git reset”
git·elasticsearch
Elastic 中国社区官方博客16 小时前
Observability:适用于 PHP 的 OpenTelemetry:EDOT PHP 加入 OpenTelemetry 项目
大数据·开发语言·人工智能·elasticsearch·搜索引擎·全文检索·php
Komorebi_999918 小时前
使用Git创建自己的分支的操作指南
git
~~李木子~~21 小时前
git仓库管理
git
Elasticsearch21 小时前
用 AI 驱动的威胁狩猎提升公共部门的网络防御
elasticsearch
白鲸开源21 小时前
实战干货:Apache DolphinScheduler 参数使用与优化总结
大数据·程序员·开源
秦jh_21 小时前
【git】远程操作
git
yumgpkpm1 天前
CMP(类Cloudera CDP 7.3 404版华为Kunpeng)与其他大数据平台对比
大数据·hive·hadoop·elasticsearch·kafka·hbase·cloudera
JZC_xiaozhong1 天前
跨系统流程如何打通?选 BPM 平台认准这三点
大数据·运维·自动化·数据集成与应用集成·业务流程管理·流程设计可视化·流程监控
中科岩创1 天前
某地公园桥梁自动化监测服务项目
大数据·人工智能·物联网·自动化