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

Repo命令使用

repo 命令与 git 类似,但它主要用于管理多个 Git 仓库的操作。以下是等效的 repo 命令:


1. 获取新仓库代码

克隆仓库

repo init -u <manifest_url> -b <branch_name>
repo sync
  • repo init:初始化 repo,指定远程清单 (manifest) 仓库的 URL 和分支。
  • repo sync:同步所有仓库的代码,相当于 git clone

切换分支

repo forall -c 'git checkout <branch_name>'
  • 切换所有仓库到指定分支。
  • 如果只想切换某个子仓库,进入目录后使用 git checkout <branch_name>

确认当前分支

repo forall -c 'git branch'
  • 显示所有子仓库的当前分支。

查看代码是否是最新

repo forall -c 'git status'
  • 显示本地修改和远程差异。

拉取远程分支代码

repo forall -c 'git pull origin <branch_name>'
  • 相当于 git pull,拉取所有子仓库的最新代码。

2. 创建新分支

创建并切换新分支

repo forall -c 'git checkout -b <new_branch_name>'
  • 创建并切换所有子仓库到新分支。

确认当前分支

repo forall -c 'git branch' 
repo forall -c 'git branch -r'
  • 分别查看本地和远程分支。

3. 提交代码

查看修改的文件

repo forall -c 'git status'

恢复文件到远程版本

repo forall -c 'git restore <file>'
  • 还原特定文件到远程版本。

添加文件

repo forall -c 'git add .' 
repo forall -c 'git add *.c *.h'
  • 添加所有文件,或者仅添加 .c.h 文件。

取消添加文件

repo forall -c 'git reset' 
repo forall -c 'git reset *.c *.h' 
repo forall -c 'git reset <file1> <file2>'
  • 取消暂存文件。

提交代码

repo forall -c 'git commit -sm "refactor: 增加处理逻辑"'
  • 提交所有子仓库的代码。

撤销上一次提交

repo forall -c 'git reset --soft HEAD~1'
  • 撤销上一次提交,但保留更改。

推送代码并创建合并请求

repo forall -c 'git push origin HEAD:mr/test/test2'
  • test:目标分支。
  • test2:临时分支。

如果使用 Gerrit:

repo upload .
  • 发送提交到代码审核系统(Gerrit)。

4. 删除远程文件

repo forall -c 'git rm <file1> <file2>' 
repo forall -c 'git commit -m "Remove unused files"' 
repo forall -c 'git push origin <branch_name>'
  • 删除文件并提交到远程。

5. 删除分支

删除本地分支

repo forall -c 'git branch -d <branch_name>'

删除远程分支

repo forall -c 'git push origin --delete <branch_name>'

查看分支

repo forall -c 'git branch -r' 
repo forall -c 'git branch' 
repo forall -c 'git branch -a'
  • 分别查看远程、本地、所有分支。

6. 常用命令

丢弃本地未提交的更改

repo forall -c 'git reset --hard'
  • 丢弃所有未提交的更改。

切换回上一个分支

repo forall -c 'git checkout -'

暂存未提交的更改

repo forall -c 'git stash' 
repo forall -c 'git stash pop'
  • stash:暂存更改。
  • pop:恢复更改。

比较本地和远程的差异

repo forall -c 'git diff origin/<branch_name>'
  • 比较本地和远程分支的差异。

这样你可以用 repo 统一管理多个 Git 仓库,简化操作流程。


http://www.kler.cn/a/545757.html

相关文章:

  • LVS集群模式
  • Ubuntu 上安装 GitLab
  • 阿里云轻量服务器docker部署nginx
  • 【NPM 版本号控制完全指南:掌握依赖管理的核心艺术】
  • 如何在 IntelliJ IDEA 中使用 Bito AI 插件
  • Java 高频面试闯关秘籍
  • GPT 系列模型发展史:从 GPT 到 ChatGPT 的演进与技术细节
  • Linux 远程文件复制传输-----scp/rsync/sftp
  • GD32 ADC 工作模式及应用详解
  • JVM——垃圾回收算法
  • js实现异步的方法
  • Vue3(2)
  • 责任链模式——C++实现
  • Kernel之Tcpdump和Netfilter
  • Node.js中的模块化:从原理到实践
  • 云原生AI Agent应用安全防护方案最佳实践(下)
  • 【安全测试】0基础新手学Web安全测试笔记(一)
  • ffmpeg --protocols
  • 【Android】设计一个圆角矩形的WebView
  • (2025)深度分析DeepSeek-R1开源的6种蒸馏模型之间的逻辑处理和编写代码能力区别以及配置要求,并与ChatGPT进行对比(附本地部署教程)