git 冲突解决(转载)

gerrit是不会解决冲突的,如果两个人同时改了一个文件的同一行,就会冲突,你将会看到Review in Progress并且最下面会有Your change could not be merged due to a path conflict.
 
如果在冲突提交者机器上解决远程冲突
cd demo
git fetch origin
git rebase origin/develop
修改冲突文件
git add .
git rebase --continue
git push origin
不会产生新的changes记录,将原changes记录重新review提交即可
git pull
如果在其它机器上解决远程冲突
cd demo
以分支为develop为例
打开Gerrit有冲突的那个网址,如 http://192.168.1.33:8080/#/c/16/ 找到Download 如下命令,执行
git fetch ssh://minggui.li@192.168.1.33:29418/demo refs/changes/16/16/1 && git checkout FETCH_HEAD
git checkout -b new_branch_name
git fetch origin
git rebase origin/develop
修改冲突文件
git add .
git rebase --continue
git push origin new_branch_name:refs/for/develop
git checkout develop
git branch -D new_branch_name
不会产生新的changes记录,将原changes记录重新review提交即可,这时在原冲突机器上直接pull会本地冲突,需要
git reset --hard HEAD^
否则会出现cannot do a partial commit during a merge.最后更新下代码
git pull
扩展阅读
撤销前一次 commit
git revert HEAD 
撤销所有本地修改
git reset --hard
撤销所有本地到上一次修改
git reset --hard HEAD^
 

1.Gerrit里点击“publish and submit”提示如下:

Your change could not be merged due to a path conflict.

Please merge (or rebase) the change locally and upload the resolution for review.

2.解决方法如下:

cd ~/projects/pan   #切换到pan项目  
git branch   #查看分支情况  
git checkout master  #选择分支  
git fetch origin  #fetch与pull的区别,自己再搜吧~  
git rebase origin/master  #查看有“CONFLICT (content): ”的地方,手工解决冲突后,下一步  
git add dev/controller/web/index.php #这只是一个举例,即要先add操作  
git rebase --continue  
git push origin HEAD:refs/for/master    #OK了

git push后,你需要在Gerrit里面再次review一次。

3.本文参考博客:《Git,Gerrit,hudson(3)--git技巧总结》

虽然对git还是有些疑惑,anyway,冲突的问题还是解决了。

 
参考:
http://johnshen0708.iteye.com/blog/1487760

http://rubyist.marsz.tw/blog/2012-01-17/git-reset-and-revert-to-rollback-commit/

原文地址:https://www.cnblogs.com/xiaoerlang/p/3810206.html