当前位置: 首页 > 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.lryc.cn/news/592722.html

相关文章:

  • 借助AI学习开源代码git0.7之三git-init-db
  • RoboBrain 2.0(具身智能论文阅读)
  • Deep Multi-scale Convolutional Neural Network for Dynamic Scene Deblurring 论文阅读
  • Visual Studio C++编译器优化等级详解:配置、原理与编码实践
  • 【iOS】消息传递和消息转发
  • gitlab-runner配置问题记录
  • 洞见AI时代数据底座的思考——YashanDB亮相2025可信数据库发展大会
  • 【C++】——类和对象(中)——默认成员函数
  • LVS(Linux Virtual Server)详细笔记(实战篇)
  • 怎么判断一个对象是不是vue的实例
  • 前端自动化测试:Jest、Puppeteer
  • Rust交叉编译自动化实战
  • 车载监控录像系统:智能安全驾驶的守护者
  • 模式结构-微服务架构设计模式
  • CUPED (Controlled-experiment using Pre-Experiment Data) 论文学习笔记
  • web安全漏洞的原理、危害、利用方式及修复方法
  • AI 驱动的仪表板:从愿景到 Kibana
  • 游戏盾能否保护业务免受DDoS攻击吗?
  • 基于单片机直流电机测速中文液晶显示设计
  • 查找服务器上存在线程泄露的进程
  • 【c++】STL-容器 list 的实现
  • 【leetcode】3201. 找出有效子序列的最大长度(1)
  • C++ -- STL-- stack and queue
  • Python基础④-装饰器、迭代器及常用函数篇
  • [Linux]如何設置靜態IP位址?
  • setTimeout、setInterval、requestAnimationFrame的使用以及区别
  • LeetCode1047删除字符串中的所有相邻重复项
  • Kubernetes Pod深度理解
  • 20250718-6-Kubernetes 调度-Pod对象:环境变量,初始容器,静态_笔记
  • LLM(Large Language Model)大规模语言模型浅析