Gerrit/Git常用操作命令

push到服务器,没有code review

bash 复制代码
git push origin HEAD:refs/heads/<branch_name>

push到服务器,需要code review

bash 复制代码
git push origin HEAD:refs/for/<branch_name>

push到draft master

bash 复制代码
git push origin HEAD:refs/drafts/master

删除服务器上的branch

bash 复制代码
git push origin --delete <branch_name>

基于某个commit切branch

bash 复制代码
git checkout -b <branch_name> <commit_id>

merge之后更新本地代码

bash 复制代码
git pull --rebase 或者 git pull -r

查看commit的代码行数

bash 复制代码
git log --stat .

修改commit提交者

bash 复制代码
git commit --amend --author shusheng.zhang@1234.com

修改commit提交时间

bash 复制代码
git commit --amend --data="2022-11-29T09:51:07"

更新子模块

bash 复制代码
git submodule update

依据别人的gerrit link开发

  1. 点击gerrit link左上角download,复制checkout命令到本地terminal中执行

  2. 执行完成会需要执行git checkout -b <branch_name>来创造自己的本地branch

  3. 如果自己单独开发,执行如下命令

    bash 复制代码
    1. git push origin HEAD:refs/heads/<branch_name> #创建属于自己的远端branch
    2. git add <changed_file>
    3. git commit -m <commit_msg>
    4. git push origin HEAD:refs/for/<branch_name> #push到远端自己的branch
  4. 如果是希望修改别人的代码,执行如下命令

    bash 复制代码
    1. git add <changed_file>
    2. git commit -m <commit_msg>
    3. git push origin HEAD:refs/for/<old_branch_name> #old_branch_name是你download的时候的branch name
相关推荐
鸿蒙程序媛2 小时前
【工具汇总】git 常用命令行汇总
大数据·git·elasticsearch
虞十三3 小时前
AtomGit 开源入门全攻略:环境搭建 + Git/Docker 实操 + 新手避坑(全平台版)
git·docker·容器
__Witheart__4 小时前
Gitblit 后台删除账户 添加权限
git
回家路上绕了弯5 小时前
IDEA 2026.1 玩转 Git Worktree:可视化操作,告别分支切换内耗
git·后端
wwj888wwj5 小时前
Ansible基础(复习3)
linux·运维·服务器·git·ansible
Slow菜鸟5 小时前
Git Worktree 使用教程
大数据·git·elasticsearch
阿民不加班20 小时前
【Git】git拉取远端但是本地存在不想提交文件处理
git
Selina K21 小时前
在windows安装git
git
周杰伦fans1 天前
如何将 Feature 分支同步到 Master 主分支:一次完整的 Git 合并实战
git
jiayi_19991 天前
git创建new branch
git