背景
工程中有一塊功能是在別的遠(yuǎn)程分支上的,然后自己的分支也是一直在更新的。現(xiàn)在要將該分支上的信功能合到自己的分支上。于是采用了git cherry-pick的方法。但是出現(xiàn)了報(bào)錯(cuò),查了許多網(wǎng)上的資料最后總結(jié)出處理沖突的步驟。
具體實(shí)現(xiàn)
輸入了:
git cherry-pick <commit id>
提示報(bào)錯(cuò):
error: could not apply ec52406... fix a bug
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'
我想應(yīng)該是和本地文件沖突了
于是輸入了:
git status
用來(lái)顯示沖突文件,然后顯示:
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 <file>..." 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
指的是我本地分支與我要合并的分支都更改的過(guò)的文件,把這些文件,用vim打開然后一個(gè)一個(gè)手動(dòng)修改。就拿第一個(gè)文件為例,輸入:
vim XJTULink-Widget/Info.plist.orig
出現(xiàn)vim界面:
(一堆代碼)
<<<<<<< ****(這是現(xiàn)在的分支)
%¥#%&(現(xiàn)在分支的語(yǔ)句)
=======
%¥#%&(沖突分支的語(yǔ)句
>>>>>>> ****(沖突的分支)
(一堆代碼)
因?yàn)檫@個(gè)文件是版本號(hào),所以明顯本地比遠(yuǎn)程分支的新,需要保留,于是刪除下面幾句話:
<<<<<<< ****(這是現(xiàn)在的分支)
=======
%¥#%&(沖突分支的語(yǔ)句
>>>>>>> ****(沖突的分支)
然后
deleted by us:
從字面就能看出,這個(gè)后面的文件指的是就是本地沒(méi)有的文件,但是遠(yuǎn)程分支是有的,因?yàn)檫@次合并就是為了獲得這些文件的,所以當(dāng)然不要?jiǎng)h除,接下來(lái)再把改好或者需要添加的文件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 "[合并]和空閑教室合并"
然后會(huì)提示
[dev_yzx bc68cff] [合并]和空閑教室合并
Author: 李堯 <liyao1021@163.com>
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
這就說(shuō)明cherry-pick完成了,不放心的話可以繼續(xù)
git status
來(lái)查看是否有遺漏的文件,如果沒(méi)有就會(huì)顯示
On branch dev_yzx
nothing to commit, working tree clean
就這樣完成一套流程了。
提示!提示!提示!提示!提示!提示!
千萬(wàn)不要開著項(xiàng)目進(jìn)行以上的流程!會(huì)沒(méi)有一點(diǎn)點(diǎn)效果!血的教訓(xùn)?。。ɡ洗筇峁┓椒ǎ簒code會(huì)幫修復(fù)的,不點(diǎn)revert就行
閑話
果然還是,一個(gè)人寫一個(gè)分支寫久了。這種git合并、處理沖突的操作非常的不熟練,竟然搞了我1天半的時(shí)間。本地分支的項(xiàng)目被毀了復(fù)原,復(fù)原繼續(xù)毀,然后好不容易步驟都對(duì)了,竟然由于開著項(xiàng)目搞得,沒(méi)有任何反應(yīng),還找了半天的原因。(其實(shí)為了寫文章 復(fù)制提示代碼 也重弄了好多次。