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

相关推荐
前端开发与ui设计的老司机1 小时前
大数据时代UI前端的智能化升级:基于机器学习的用户意图预测
大数据·ui
oneslide1 小时前
elasticsearch备份恢复
大数据·elasticsearch·搜索引擎
rui锐rui1 小时前
大数据学习6:Sqoop数据迁移工具
大数据·学习·sqoop
小牛头#6 小时前
clickhouse 各个引擎适用的场景
大数据·clickhouse·机器学习
中微子7 小时前
Git Rebase 详解:概念、原理与实战示例
git
lifallen8 小时前
Paimon LSM Tree Compaction 策略
java·大数据·数据结构·数据库·算法·lsm-tree
元宇宙时间8 小时前
全球发展币GDEV:从中国出发,走向全球的数字发展合作蓝图
大数据·人工智能·去中心化·区块链
荔枝吻11 小时前
【保姆级喂饭教程】Windows下安装Git Flow
windows·git·git flow
张先shen11 小时前
Elasticsearch RESTful API入门:基础搜索与查询DSL
大数据·spring boot·elasticsearch·搜索引擎·全文检索·restful