1
git修改合并提交
admin edited this page 2025-12-25 17:31:02 +08:00
This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

总结合并提交的命令步骤:

1. 检查当前状态

git status
git log --oneline

2. 修改最新提交(将暂存区修改合并到最新提交)

# 修改最新提交(会打开编辑器修改提交信息)
git commit --amend

# 或者不改提交信息直接合并
git commit --amend --no-edit

# 或者修改作者信息
git commit --amend --author="正确用户名 <正确邮箱>"

3. 修改多个提交的作者信息(如果需要)

# 交互式重写提交历史
git rebase -i HEAD~n  # n是要修改的提交数量

# 在编辑器中,将需要修改的提交前的"pick"改为"edit"
# 然后对每个标记为edit的提交
git commit --amend --author="正确用户名 <正确邮箱>" --no-edit
git rebase --continue

4. 推送到 Gerrit

# 推送到master分支评审
git push origin HEAD:refs/for/master

# 推送到特定分支评审
git push origin HEAD:refs/for/分支名

5. 推送成功后验证

访问 Gerrit 链接查看评审状态:

http://101.43.95.130:8082/c/zhini_im/+/7

重要提示:

  1. 确保 Git 配置正确

    git config --global user.email "你在Gerrit注册的邮箱"
    git config --global user.name "你的Gerrit用户名"
    
  2. 如果推送失败,检查邮箱是否匹配:

    # 查看当前提交的作者信息
    git log --pretty=format:"%an <%ae>" -1
    
  3. 更新已推送到 Gerrit 的提交

    # 修改提交后强制推送更新
    git commit --amend
    git push origin HEAD:refs/for/master
    # Gerrit 会自动识别为同一个变更的更新
    
  4. 查看远程仓库配置

    git remote -v
    

你现在可以:

  1. 访问 http://101.43.95.130:8082/c/zhini_im/+/7 查看你的变更
  2. 等待评审或自己进行代码审查
  3. 如果还有修改,可以继续使用 git commit --amend 然后重新推送

恭喜你成功将代码推送到 Gerrit