Git: 如何修复gerrit merge conflict状态

当A和B在Gerrit上分别提交了修改同一文件的变更时,会出现合并冲突。解决方法包括:首先同步远程代码,然后使用git rebase进行变基操作。在出现冲突时,手动编辑文件,保留所需更改并解决冲突,接着使用git add标记解决冲突,最后运行git rebase --continue完成变基。成功后,提交并push到Gerrit,冲突状态将消除。
摘要由CSDN通过智能技术生成

A本地修改了某个文件File,B本地也修改了这个文件File,他们都先后git push到了gerrit上,这个时候reviewer无论先进谁的提交,gerrit上另一笔提交的状态都会显示merge conflict,那如何更新这一笔change,而不是Abandon然后再提一个change呢,假设A的提交了先进了,要修改B的change。

  1. 先同步服务器代码
git remote update

  1. rebase
git rebase remote_branch

会出现如下提示:

First, rewinding head to replay your work on top of it...
Applying: your_patch
Using index info to reconstruct a base tree...
M     your_modified_file
Falling back to patching base and 3-way merge...
Auto-merging your_modified_file
CONFLICT (content): Merge conflict in your_modified_file
Recorded preimage for 'your_modified_file'
Failed to merge in the changes.
Patch failed at 0001 your_patch
The copy of the patch that failed is found in:
   /your_prj_path/.git/rebase-apply/patch

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

这个时候git log就能看到A的提交。

git status能看到此时正在rebasing,要你修复冲突后再运行continue rebase:

rebase in progress; onto 5ac5126
You are currently rebasing.
  (fix conflicts and then run "git rebase --continue")
  (use "git rebase --skip" to skip this patch)
  (use "git rebase --abort" to check out the original branch)

Unmerged paths:
  (use "git reset HEAD <file>..." to unstage)
  (use "git add <file>..." to mark resolution)

    both modified:      your_conflict_file

no changes added to commit (use "git add" and/or "git commit -a")

  1. 修改冲突文件

打开冲突文件,能发现A和B的提交都在里面,手动编辑这个文件让他保持A的提交内容,然后再加上B的修改。

  1. mark resolution
git add .

add后会提示冲突修复了。

rebase in progress; onto 5ac5126
You are currently rebasing.
  (all conflicts fixed: run "git rebase --continue")

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    modified:   your_file

  1. 继续rebase
git rebase --continue

成功后会提示:

Applying: your_patch
Recorded resolution for 'your_modified_file'.

再git log方法B的提交在A的后面。

  1. 提交

push后gerrit这一笔提交status的merge conflict已经没有了,History里会显示:

Uploaded patch set 2.

OK, Done.

转自:

Git: 如何修复gerrit merge conflict状态 - TJ的技术博客
http://www.tjtech.me/how-to-fix-merge-conflict-on-gerrit.html

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值