Git 与 Gerrit 应用1

来源:互联网 发布:手机淘宝怎么投诉买家 编辑:程序博客网 时间:2024/05/29 14:58

Git 与 Gerrit 应用1—>遇到 Conflict

使用git总有一天会遇到Conflict,所以简单讲一下解决办法

1.如果在 git push 之出现类似下列信息,表示有 conflict 发生:

! [rejected] master -> master (fetch first)
error: failed to push some refs to ‘http://ryan.chang@172.18.51.25:8082/Sandbox’
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: ‘git pull …’) before pushing again.
hint: See the ‘Note about fast-forwards’ in ‘git push –help’ for details.
2.Hint 里包含了不少信息,总之就是有其他人先commit了,但现在gerrit设定只收‘fast-forwad’的commit,所以先把其他人改的版本抓下來:

$ git fetch
3.接下来要想办法修改 local repository 的历史,好让 gerrit server 愿意收 commit … 用 git rebase

4.其实通常来说 git 会很聪明的做完调整,所以如果在 git rebase 之后沒有看到什麼可怕的信息,应该就可以回到 git push 的路线,再次把 commit 推上去了。但这里还是讲一下真的 conflict 的状况,你应该会看到类似下面的信息:

$ git rebase
First, rewinding head to replay your work on top of it…
Applying: Hello again!
Using index info to reconstruct a base tree…
M foo
Falling back to patching base and 3-way merge…
Auto-merging foo
CONFLICT (content): Merge conflict in foo
Failed to merge in the changes.
Patch failed at 0001 Hello again!
The copy of the patch that failed is found in:
…/Sandbox/.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”.
5.那么来merge 吧,敲 git mergetool,[Enter],

6.改成你最后希望的样子之后,存档,离开编辑器,告诉 git 可以继续 rebase 了:

$ git rebase –continue
Applying: Hello again!
7.rebase 完成后,就可以回到 git push 路线去了

0 0