編程學習網 > 編程教程 > SVN 教程
2015
10-18

SVN解決沖突

清華大佬耗費三個月吐血整理的幾百G的資源,免費分享!....>>>

Tom 決定為他們的項目添加README文件。因此,他創造了README文件,并添加到該TODO列表。在加入這個文件庫在修訂版本6。

[tom@CentOS trunk]$ cat README 
/* TODO: Add contents in README file */

[tom@CentOS trunk]$ svn status
?       README

[tom@CentOS trunk]$ svn add README 
A         README

[tom@CentOS trunk]$ svn commit -m "Added README file. Will update it's content in future."
Adding         trunk/README
Transmitting file data .
Committed revision 6. 

Jerry 檢出最新的代碼,這是修訂版本6。他就立刻開始工作。經過幾個小時的Tom更新README文件并提交了他的變化。修改README這個樣子。

[tom@CentOS trunk]$ cat README 
* Supported operations:

1) Accept input
2) Display array elements

[tom@CentOS trunk]$ svn status
M       README

[tom@CentOS trunk]$ svn commit -m "Added supported operation in README"
Sending        trunk/README
Transmitting file data .
Committed revision 7.

現在,庫是修訂版本7 Jerry的工作拷貝是過時了。Jerry 還更新README文件,并嘗試提交他的變化。

Jerry' 的README文件看起來像這樣。

[jerry@CentOS trunk]$ cat README 
* File list

1) array.c	Implementation of array operation.
2) README	Instructions for user.

[jerry@CentOS trunk]$ svn status
M       README

[jerry@CentOS trunk]$ svn commit -m "Updated README"
Sending        trunk/README
svn: Commit failed (details follow):
svn: File or directory 'README' is out of date; try updating
svn: resource out of date; try updating

Step 1: 查看沖突

這是好事。Subversion的檢測README文件已經改變,因為最后一次更新。因此,Jerry 更新自己的工作副本。

[jerry@CentOS trunk]$ svn up
Conflict discovered in 'README'.
Select: (p) postpone, (df) diff-full, (e) edit,
        (mc) mine-conflict, (tc) theirs-conflict,
        (s) show all options:

Subversion抱怨README文件有沖突,Subversion不知道如何解決這個問題。所以Jerry 選擇 df 查看沖突。

[jerry@CentOS trunk]$ svn up
Conflict discovered in 'README'.
Select: (p) postpone, (df) diff-full, (e) edit,
        (mc) mine-conflict, (tc) theirs-conflict,
        (s) show all options: df
--- .svn/text-base/README.svn-base	Sat Aug 24 18:07:13 2013
+++ .svn/tmp/README.tmp	Sat Aug 24 18:13:03 2013
@@ -1 +1,11 @@
-/* TODO: Add contents in README file */
+<<<<<<< .mine
+* File list
+
+1) array.c	Implementation of array operation.
+2) README	Instructions for user.
+=======
+* Supported operations:
+
+1) Accept input
+2) Display array elements
+>>>>>>> .r7
Select: (p) postpone, (df) diff-full, (e) edit, (r) resolved,
        (mc) mine-conflict, (tc) theirs-conflict,
        (s) show all options:

Step 2: 延緩沖突

Jerry 選擇推遲(p)選項,這樣他就可以解決沖突。

Select: (p) postpone, (df) diff-full, (e) edit, (r) resolved,
        (mc) mine-conflict, (tc) theirs-conflict,
        (s) show all options: p
C    README
Updated to revision 7.
Summary of conflicts:
  Text conflicts: 1

在文本編輯器中打開README文件后,他意識到,Subversion會包含Tom 的代碼和他沖突標記代碼。

[jerry@CentOS trunk]$ cat README
<<<<<<< .min
* File list

1) array.c	Implementation of array operation.
2) README	Instructions for user.
=======
* Supported operations:

1) Accept input
2) Display array elements
>>>>>>> .r7

Jerry 希望 Tom 同他的變化一起修改,所以他只是刪除了行包含沖突標記。

所以修改后的README文件會如下這個樣子。

[jerry@CentOS trunk]$ cat README
* File list

1) array.c	Implementation of array operation.
2) README	Instructions for user.

* Supported operations:

1) Accept input
2) Display array elements

Jerry 解決沖突并提交,并讓他重試。

[jerry@CentOS trunk]$ svn commit -m "Updated README"
svn: Commit failed (details follow):
svn: Aborting commit: '/home/jerry/project_repo/trunk/README' remains in conflict
 
[jerry@CentOS trunk]$ svn status
?       README.r6
?       README.r7
?       README.mine
C       README

Step 3: 解決沖突

這里是C字母表示有README文件沖突。Jerry 解決沖突,但沒有告訴Subversion他解決沖突。他使用解決命令通知Subversion有關解決沖突

[jerry@CentOS trunk]$ svn resolve --accept=working README
Resolved conflicted state of 'README'

[jerry@CentOS trunk]$ svn status
M       README

[jerry@CentOS trunk]$ svn commit -m "Updated README"
Sending        trunk/README
Transmitting file data .
Committed revision 8.

掃碼二維碼 獲取免費視頻學習資料

編程學習