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

相关推荐
火火PM打怪中3 小时前
产品经理如何绘制服务蓝图(Service Blueprint)
大数据·产品经理
Elastic 中国社区官方博客11 小时前
在 Windows 上使用 Docker 运行 Elastic Open Crawler
大数据·windows·爬虫·elasticsearch·搜索引擎·docker·容器
Komorebi_999912 小时前
Git常用指令
git·web
一切顺势而行12 小时前
Flink cdc 使用总结
大数据·flink
一小池勺14 小时前
🚀 Git 如何让文件存在于远程仓库却不被本地追踪?
git·github
淦暴尼14 小时前
基于spark的二手房数据分析可视化系统
大数据·分布式·数据分析·spark
Ashlee_code15 小时前
裂变时刻:全球关税重构下的券商交易系统跃迁路线图(2025-2027)
java·大数据·数据结构·python·云原生·区块链·perl
Flink_China15 小时前
淘天AB实验分析平台Fluss落地实践:更适合实时OLAP的消息队列
大数据·flink
阿里云大数据AI技术16 小时前
云上AI推理平台全掌握 (4):大模型分发加速
大数据·人工智能·llm
五月高高16 小时前
Idea使用git不提示账号密码登录,而是输入token问题解决
git