当前位置: 首页 > news >正文

如何将本地Git仓库推送到远程仓库的一个文件中并保留Commit记录

将本地Git仓库推送到远程仓库的一个文件中并保留Commit记录

当我们在本地用Git管理了一段代码,过了一段时间后想把它推送到远程仓库,但是又不想放到根目录下,因为我还需要在远程仓库中加入其它内容,比如硬件,文档等,这时怎么操作呢?这时我们就要用到Git的Subtree功能

# /path/to/your/local/repo: path to your local repo root, could be absolute path or relative path to current path
$ git remote add localrepo /path/to/your/local/repo# fetch
$ git fetch localrepo# new_folder/under/remote/root: a new folder under your remote repo, which should not exist yet, to contain the local repo, beware that the parent folder of the local repo is not copied,  like if you local repo is under foler <local_repo>, the folder <local_repo> won't be copied, only the contents under <local_repo> will be copied.
# for example, if you would like to merge you <local_repo> to <code/motor_control> under remote root, the command should be : git  subtree add --prefix=code/motor_control localrepo master
# Make sure the branch name of the local repo is 'master', otherwise change accordingly, if you are not sure, use command: 'git remote show localrepo' to get the branch name
$ git subtree add --prefix=new_folder/under/remote/root localrepo master# Finally push the commit to remote:
$ git push origin master
http://www.dtcms.com/a/286289.html

相关文章:

  • 对于编码电机-520直流减速电机
  • 硬核电子工程:从硅片到系统的全栈实战指南—— 融合电路理论、嵌入式开发与PCB设计的工程艺术
  • 正则表达式完全指南:从入门到实战
  • Web3加密货币交易:您需要知道的所有信息
  • 五分钟掌握 TDengine 数据文件的工作原理
  • 《设计模式之禅》笔记摘录 - 8.命令模式
  • 【Mediatek】AN7563搭建编译环境操作说明
  • 1 初识C++
  • 【java 安全】 IO流
  • 20250718-3-Kubernetes 应用程序生命周期管理-Pod对象:存在意义_笔记
  • Android性能优化之包体积优化
  • C++算法竞赛篇:DevC++ 如何进行debug调试
  • Django 实战:I18N 国际化与本地化配置、翻译与切换一步到位
  • 第7天 | openGauss中一个数据库中可以创建多个模式
  • 51c视觉~合集13
  • 互联网医疗健康服务包的核心内容架构与模块组合
  • 小记_想写啥写啥_实现行间的Latex公式_VScode始终折叠大纲
  • 构建直播平台大体的流程
  • gcc 源码阅读---编译器后端实现的关键数据结构
  • DOM笔记
  • 什么是KL散度
  • Android-EDLA【CTS】CtsInputMethodTestCases存在fail
  • 4G模块 A7680发送中文短信到手机
  • 高精度减法模版和分析(C++版本)
  • 嵌入式八股(持续更新)
  • 【算法训练营Day14】二叉树part4
  • windows终端美化(原生配置+Oh My Posh主题美化)
  • 客诉:危机到信任的重建
  • Flutter 应用如何设计通知服务
  • Flutter——Android原生View是如何通过Flutter进行加载