SVN: 沖突解決 合并別人的修改(待整理)

This tutorial is walkthough on how to resolve a conflict in svn (subversion) 這個手冊是解決svn沖突的攻略 First I will make a test.txt 首先,我創(chuàng)建了一個名為test.txt的文件(在svn服務(wù)器端),并錄入如下內(nèi)容 test Now I will commit the changes 現(xiàn)在我們提交剛剛添加的內(nèi)容 C:\workspace\test>svn ci -m "making a starting point" Sending . Sending test.txt Transmitting file data . Committed revision 2. Suppose we have 2 users. User1 and User2. Both of them will get and update from svn 假設(shè)我們有用戶1和用戶2兩個人通過svn客戶端獲取svn服務(wù)器端的文件test.txt C:\workspace\test>svn up A test.txt At revision 2. Now User1 will change the file to: 現(xiàn)在用戶1更改文件test.txt內(nèi)容為如下 User1 is making a conflict test He then commits his changes 然后用戶1提交剛才的更改 C:\workspace\test>svn ci -m "User1 starting a conflict" Sending . Sending test.txt Transmitting file data . Committed revision 3. User2 now comes along and changes his local copy of the file not knowing that it has already been updated by User1 on the server. 用戶2也對文件test.txt做了更改,此時他并不知道用戶1做了更改并已提交。 test User2 making a conflict When he tries to commit he will get and error from svn. 當(dāng)用戶2修改文件test.txt完畢后,準(zhǔn)備提交時出錯。 svn: Commit failed (details follow): svn: File or directory 'test.txt' is out of date; try updating svn: resource out of date; try updating So User2 performs an update 根據(jù)錯誤提示,用戶2更新了文件test.txt(此時發(fā)生了沖突) C:\workspace\test>svn up Conflict discovered in 'test.txt'. Select: (p) postpone, (df) diff-full, (e) edit, (mc) mine-conflict, (tc) theirs-conflict, (s) show all options: svn detects that theres a conflict here and require you to take some kind of action. If you type ‘s’ here you will get a list of the commands and meaning 如果你輸入s選項,則會列出所有svn解決沖突的選項,如下所示: (e) edit - change merged file in an editor #直接進入編輯 (df) diff-full - show all changes made to merged file #顯示更改至目標(biāo)文件的所有變化 (r) resolved - accept merged version of file (dc) display-conflict - show all conflicts (ignoring merged version) #顯示所有沖突 (mc) mine-conflict - accept my version for all conflicts (same) #沖突以本地為準(zhǔn) (tc) theirs-conflict - accept their version for all conflicts (same) #沖突以服務(wù)器為準(zhǔn) (mf) mine-full - accept my version of entire file (even non-conflicts)#完全以本地為準(zhǔn) (tf) theirs-full - accept their version of entire file (same) #完全以服務(wù)器為準(zhǔn) (p) postpone - mark the conflict to be resolved later #標(biāo)記沖突,稍后解決 (l) launch - launch external tool to resolve conflict (s) show all - show this list 【選擇處理方式一:df】 If you type ‘df’ it will show you a all the conflicts in the following format 選擇選項df,則會按如下格式顯示所有沖突 Select: (p) postpone, (df) diff-full, (e) edit, (mc) mine-conflict, (tc) theirs-conflict, (s) show all options: df --- .svn/text-base/test.txt.svn-base Tue Aug 10 10:59:38 2010 +++ .svn/tmp/test.txt.2.tmp Tue Aug 10 11:33:24 2010 @@ -1 +1,3 @@ -test \ No newline at end of file +<<<<<<< .mine +test User2 making conflict======= +User1 is making a conflict test>>>>>>> .r3 ‘e’ option will open the conflicted file in the text editor that you configured for svn to use. In this case it will show <<<<<<< .mine test User2 making conflict======= User1 is making a conflict test>>>>>>> .r3 You can resolve the conflict here by changing the text to what you desire. For example: 你可以解決沖突通過改變文件內(nèi)容,例如vim test.txt User1 is making a conflict test User2 making conflict save your changes and exit your text editor and it will give you the conflict options again. Now if you use the ‘r’ it will mark the file is merged with a ‘G’. A status of ‘G’ means there was a conflict and it has been resolved. 保存更改,又出現(xiàn)剛才的選項。此時你使用r選項,則會合并文件。如下所示: Select: (p) postpone, (df) diff-full, (e) edit, (r) resolved, (mc) mine-conflict, (tc) theirs-conflict, (s) show all options: e Select: (p) postpone, (df) diff-full, (e) edit, (r) resolved, (mc) mine-conflict, (tc) theirs-conflict, (s) show all options: r G test.txt Updated to revision 3. you can now check the status with svn status. You see that test.txt is marked as ‘M’ all thats left to do is commit. 檢查svn狀態(tài),你會發(fā)現(xiàn)文件test.txt前面已變成M C:\workspace\test2>svn st M test.txt C:\workspace\test2>svn ci -m "conflict resolved" Sending test.txt Transmitting file data . Committed revision 4. 【選擇處理方式二:p】 Sometimes the conflicts are a bit more extensive and it requires more time or better tools to resolve the conflict in these cases you can chose ‘p’ to postpone the resolution. 有時,沖突會復(fù)雜一些,可能需要借助其他工具才能解決,這時你可以使用選項p Select: (p) postpone, (df) diff-full, (e) edit, (r) resolved, (mc) mine-conflict, (tc) theirs-conflict, (s) show all options: p C test.txt Updated to revision 3. Summary of conflicts: Text conflicts: 1 Now if you look in your directory you will see that svn has created a few extra files for you. 此時,查看當(dāng)前文件夾下,出現(xiàn)了如下幾個文件 08/10/2010 11:44 AM 94 test.txt 08/10/2010 11:44 AM 26 test.txt.mine 08/10/2010 11:44 AM 27 test.txt.r2 08/10/2010 11:44 AM 31 test.txt.r3 The test.txt file is now a file with both User2 and User1′s changes but marked. 文件test.txt包含了用戶1和用戶2的更改。 <<<<<<< .mine test User2 making conflict======= User1 am making a conflict test>>>>>>> .r3 test.txt.mine is User2′s copy. 文件.txt.mine保存了用戶2的內(nèi)容 test User2 making conflict test.txt.r2 is the original base copy 文件.txt.r2是未沖突前的內(nèi)容 test test.txt.r3 is the copy User1 commited 文件.txt.r3保存了用戶1的內(nèi)容 User1 is making a conflict test At this point you can choose your favorite merge tools to merge the differences in a file. 這種情況下,你可以選擇自己喜歡的對比工具,查看差別。 I suggest merging the differences into test.txt and the do a 我建議和并不同至文件test.txt中,如果如下命令: C:\workspace\test>svn resolve --accept working test.txt Resolved conflicted state of 'test.txt' You can also use any of the other files if you wanted to and just pass resolve –accept a different argument. Here are the valid arguments 當(dāng)然,你也可以使用其他文件,使用resolve -accept 加其他參數(shù),共6個 實例: svn resolve mail.sh --accept 'mine-conflict' #解決沖突。 svn resolved mail.sh #告知svn。4個文件中的其他3個消失 (1)#svn resolve –accept base Choose the file that was the BASE revision before you updated your working copy. That is, the file that you checked out before you made your latest edits. 使用1.txt.r2作為最后提交的版本 (2)#svn resolve –accept working Assuming that you've manually handled the conflict resolution, choose the version of the file as it currently stands in your working copy. 使用當(dāng)前拷貝即test.txt作為最后提交的版本 (3)#svn resolve –accept mine-full Resolve all conflicted files with copies of the files as they stood immediately before you ran svn update. 使用test.txt.mine作為最后提交的版本 (4)#svn resolve –accept theirs-full Resolve all conflicted files with copies of the files that were fetched from the server when you ran svn update. 使用test.txt.r3作為最后提交的版本 (5)#svn resolve –accept mine-conflict 沖突的部分以本地修改為準(zhǔn) (6)#svn resolve –accept theirs-conflict 沖突的部分以服務(wù)器端修改為準(zhǔn) 執(zhí)行一下:svn resolved test.txt。 Now you are ready to commit. 然后提交 C:\workspace\test>svn ci -m "conflict resolved" Sending test.txt Transmitting file data . Committed revision 4.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 228,443評論 6 532
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 98,530評論 3 416
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 176,407評論 0 375
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經(jīng)常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 62,981評論 1 312
  • 正文 為了忘掉前任,我火速辦了婚禮,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 71,759評論 6 410
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 55,204評論 1 324
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,263評論 3 441
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 42,415評論 0 288
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 48,955評論 1 336
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 40,782評論 3 354
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 42,983評論 1 369
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,528評論 5 359
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 44,222評論 3 347
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,650評論 0 26
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 35,892評論 1 286
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 51,675評論 3 392
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 47,967評論 2 374

推薦閱讀更多精彩內(nèi)容