git 处理冲突步骤

背景


工程中有一块功能是在别的远程分支上的,然后自己的分支也是一直在更新的。现在要将该分支上的信功能合到自己的分支上。于是采用了git cherry-pick的方法。但是出现了报错,查了许多网上的资料最后总结出处理冲突的步骤。

具体实现


输入了:

git cherry-pick 

提示报错:

error: could not apply ec52406... fix a bug
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add ' or 'git rm '
hint: and commit the result with 'git commit'

我想应该是和本地文件冲突了

于是输入了:

git status

用来显示冲突文件,然后显示:

On branch dev_yzx
You are currently cherry-picking commit ec52406.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Unmerged paths:
  (use "git add/rm ..." as appropriate to mark resolution)

    both modified:   XJTULink-Widget/Info.plist
    both modified:   XJTULink-iOS/Info.plist
    deleted by us:   XJTULink-iOS/LKClassroomModule/LKClassroomModule/Model/BuildingModel.m
    deleted by us:   XJTULink-iOS/LKClassroomModule/LKClassroomModule/View/ClassroomViewController.m
    deleted by us:   XJTULink-iOS/LKClassroomModule/LKClassroomModule/View/IdleClassroomViewController.m
    deleted by us:   XJTULink-iOS/LKClassroomModule/LKClassroomModule/View/Views/IdleClassroomCell.m
    deleted by us:   XJTULink-iOS/LKClassroomModule/LKClassroomModule/View/Views/IdleClassroomCell.xib

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

这里的

both modified

指的是我本地分支与我要合并的分支都更改的过的文件,把这些文件,用vim打开然后一个一个手动修改。就拿第一个文件为例,输入:

vim XJTULink-Widget/Info.plist.orig

出现vim界面:

(一堆代码)
<<<<<<< ****(这是现在的分支)
%¥#%&(现在分支的语句)
=======
%¥#%&(冲突分支的语句
>>>>>>> ****(冲突的分支)
(一堆代码)

因为这个文件是版本号,所以明显本地比远程分支的新,需要保留,于是删除下面几句话:

<<<<<<< ****(这是现在的分支)
=======
%¥#%&(冲突分支的语句
>>>>>>> ****(冲突的分支)

然后

deleted by us:

从字面就能看出,这个后面的文件指的是就是本地没有的文件,但是远程分支是有的,因为这次合并就是为了获得这些文件的,所以当然不要删除,接下来再把改好或者需要添加的文件add和commit

git add XJTULink-Widget/Info.plist
git add XJTULink-iOS/Info.plist
git add XJTULink-iOS/LKClassroomModule/LKClassroomModule/Model/BuildingModel.m
git add XJTULink-iOS/LKClassroomModule/LKClassroomModule/View/ClassroomViewController.m
git add XJTULink-iOS/LKClassroomModule/LKClassroomModule/View/IdleClassroomViewController.m
git add XJTULink-iOS/LKClassroomModule/LKClassroomModule/View/Views/IdleClassroomCell.m
git add XJTULink-iOS/LKClassroomModule/LKClassroomModule/View/Views/IdleClassroomCell.xib

git commit -m "[合并]和空闲教室合并"

然后会提示

[dev_yzx bc68cff] [合并]和空闲教室合并
 Author: 李尧 
 Date: Wed Apr 19 00:41:37 2017 +0800
 5 files changed, 600 insertions(+)
 create mode 100644 XJTULink-iOS/LKClassroomModule/LKClassroomModule/Model/BuildingModel.m
 create mode 100755 XJTULink-iOS/LKClassroomModule/LKClassroomModule/View/ClassroomViewController.m
 create mode 100755 XJTULink-iOS/LKClassroomModule/LKClassroomModule/View/IdleClassroomViewController.m
 create mode 100755 XJTULink-iOS/LKClassroomModule/LKClassroomModule/View/Views/IdleClassroomCell.m
 create mode 100755 XJTULink-iOS/LKClassroomModule/LKClassroomModule/View/Views/IdleClassroomCell.xib

这就说明cherry-pick完成了,不放心的话可以继续

git status

来查看是否有遗漏的文件,如果没有就会显示

On branch dev_yzx
nothing to commit, working tree clean

就这样完成一套流程了。

提示!提示!提示!提示!提示!提示!

千万不要开着项目进行以上的流程!会没有一点点效果!血的教训!!(老大提供方法:xcode会帮修复的,不点revert就行

闲话


果然还是,一个人写一个分支写久了。这种git合并、处理冲突的操作非常的不熟练,竟然搞了我1天半的时间。本地分支的项目被毁了复原,复原继续毁,然后好不容易步骤都对了,竟然由于开着项目搞得,没有任何反应,还找了半天的原因。(其实为了写文章 复制提示代码 也重弄了好多次。

你可能感兴趣的:(git 处理冲突步骤)