SVN 解決沖突

2018-08-12 21:14 更新

SVN 解決沖突

Tom決定給他的工程添加一個 README 文件,于是他創(chuàng)建了這個文件并在其中添加了 TODO 列表。添加完成之后,該文件的存放處位于 revision 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 檢出了位于 revision 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.

現(xiàn)在,倉庫位于修改版本 7,并且 Jerry 的工作副本已經(jīng)過期。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

第一步:視圖沖突

Subversion 已經(jīng)檢測出 README 自上次更新后文件已經(jīng)更改。所以,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:

第二步:推遲沖突

接下來 Jerrypostpone(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 文件后,Jerry 意識到 Subversion 已經(jīng)包含了 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

第三步:解決沖突

在上面的提交中,字母 C 指示說有一個沖突在 README 文件。Jerry 解決了沖突但并沒有告訴 Subversion 已經(jīng)解決了沖突。 他使用了 resolve 命令通知 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.
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號