目录
[合并与打 Tag](#合并与打 Tag)
[Commit 模板](#Commit 模板)
查看与提交记录
bash
# 查看最近一次提交
git log -1
git log --oneline -1
git log --oneline -5
# 进入vim,修改最近一次 commit
git commit --amend
# 查看差异(工作区 vs 暂存区)
git diff
# 查看差异(本地分支 vs 远程分支)
git diff myBL4.1 origin/renault_pcu/BL4.1
git diff <本地分支> <远程分支>
提交代码
bash
#添加所有改动
git add .
git add . --ignore-error
git status
# 提交,带 message
git commit -m "feat:描述提交的功能"
# 修改最后一次提交(不改内容,只改 message)
git commit --amend -m "fix: 修正提交说明"
提交规范:feat | fix | refactor | chore | docs
分支管理
bash
# 查看所有分支
git branch
git branch -r
git branch -a
git branch -vv
# 新建分支并切换(会从当前分支复制完整的提交历史和源代码)
git checkout -b myBL4.1.4
# 切换到已有分支
git checkout myBL4.1
git checkout origin/renault_pcu/BL4.1
# 删除本地分支
git branch -D tempCheckBL4.1
# 重命名本地分支
git branch -m <旧分支名> <新分支名>
# 新建一个空白分支
git checkout --orphan empty-branch
git rm -rf .
git commit --allow-empty -m "Initial commit in empty branch "
远程分支操作
bash
# 将本地分支与远程分支关联
git branch --set-upstream-to=origin/renault_pcu/BL4.1.4 myBL4.1.4
# 获取远程最新分支状态(不会合并)
git fetch origin
# 拉取并合并远程分支
git pull origin myBL4.1
# 推送本地分支到远程
git push origin myBL4.1
# 推送到 Gerrit 代码审查
git push origin myBL4.1:refs/for/renault_pcu/BL4.1
git push origin <本地分支>:<代码审查请求><远程分支>
同步与回滚
bash
#把本地分支重置为远程最新状态
git reset --hard origin/renault_pcu/BL4.1
# 撤销未提交的修改
git checkout -- filename
# 撤销暂存区的文件(保持修改)
git restore --staged filename
# 回退到指定提交
git reset --hard <commit-id>
切换到远程分支,对远程仓库做检查
bash
#同步远程分支到本地
git fetch origin
# 临时切远程分支
git checkout -b tempCheckBL4.1 origin/renault_pcu/BL4.1
# 看完后清理->先切离temp分支
git checkout myBL4.1
# 看完后清理->再删除temp分支
git branch -D tempCheckBL4.1
合并与打 Tag
bash
# 查看最近一次 commit 简要信息
git log -1 --oneline
# 合并 feature 分支到当前分支
git merge feature-driver
# 打 Tag(带说明)
git tag -a vBL4.1_merge_BL4.1.6 -m "add BL4.1.6 to BL4.1 0725"
# 推送 Tag
git push origin vBL4.1_merge_BL4.1.6
Tag管理
bash
# 查看所有 Tag
git tag
# 查看远程所有 Tag
git ls-remote --tags origin
#删除本地 Tag
git tag -d v0.1.0
# 删除远程 Tag
git push origin :refs/tags/v0.1.0
# Gerrit网页中新建tag的格式
renault_pcu/tag_xxx
renault_pcu/tag_BL4.1MergeFromBL4.1.6
Commit 模板
bash
add 4.1.6 XCU_Real_xxx_BL4.1.4:BL4.1
add 4.1.6 XCU_Real_xxx_BL4.1.4:BL4.1
Test: ok
Author: xxx@xxx.com
Ticket: 999999
Signed-off-by: xxx xxx@xxx.com
其中:type in summary must be one of "new/created/fix/modify/patch/refactor/add"