git多人协作代码合并流程

Git协作开发方式1:

1、git commit,提交修改到git 本地Cache中;

2、git pull --rebase origin branchname,通过rebase方式合并代码;

3、git push -u origin branchename,将所有修改提交到远端。

 

该方式适合于所有代码commit后,他人获取可以顺利编译运行的情况。

 

步骤2可能产生文件冲突。

例如:

Auto-merging products/xxx/res/ccb/Node.ccbi

CONFLICT (content): Merge conflict in products/xxx/res/ccb/Node.ccbi

修改方法为:

1)手工修改冲突文件;

2)用本地的或者他人的文件替换冲突文件。(注意:ours/theirs的实际作用与字面意义是相反的!!!

a、以本地文件为准:git checkout --theirs products/xxx/res/ccb/Node.ccbi。(The option will keep the original one we had.)

b、以他人提交文件为准:git checkout --ours products/xxx/res/ccb/Node.ccbi。(The option will keep the version of the file that you merged in.)

 

修复后,执行命令:

git add products/xxx/res/ccb/Node.ccbi

git rebase --continue

 

重复上述方法,一直到rebase结束。

中间如果存在以下情况

Applying: Fixed unit test

No changes - did you forget to use 'git add'? If there is nothing left to stage, chances are that something else already introduced the same changes; you might want to skip this 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".

这种情况,很可能是你修复 products/xxx/res/ccb/Node.ccbi 的方式为从别处拷贝,而不是手工修复冲突处,所以系统认为文件没有变化。解决方法如下:

执行命令:

git config --global core.trustctime false

 或者手工修改。参考文章

 

如果本地修暂时无法commit的话,则可以采取stash方式更新他人代码。

1、git stash --include-untracked

2、git pull --rebase origin branchname

3、git stash pop

4、修复可能存在的merge文件冲突。

 

采用git pull --rebase,而不是默认的git merge,请参考文章

猜你喜欢

转载自song020cn.iteye.com/blog/2207701