XCode使用自帶SVN,SVN命令


轉載http://blog.sina.com.cn/s/blog_68661bd80101phpy.html

這兩天響應老板要求,把所有代碼放到公司的SVN服務器上,按照我的想法肯定是就蘋果組建一個服務器,然后內部版本控制,自帶的Xcode就有這個功能,之前也這么做過,但是xcode4.X系列SVN還是很好用,自從升級到Xcode5之后還沒弄過。今天試了一下午還是沒完全明白,眼看弄不出來,就直接用命令行了,不過一些簡單的東西還是試出來了。

1.如何使用Xcode5  SVN從公司服務器 check out項目

iOS開發XCODE5 <wbr>SVN配置 <wbr>使用辦法

iOS開發XCODE5 <wbr>SVN配置 <wbr>使用辦法

  1. Choose Source Control > Check Out.

  2. Select the repository you want to check out, and click Next.

    You can select your repository from the Repositories tab, the Favorites tab, or the Recents tab. If you know the location of the repository you want to check out, you can also enter the address manually.

  3. If Xcode is unable to automatically identify the trunk and branches, use the browser window to select the correct project location, and click Next.

  4. In the Checkout window, select the branches and working copies to check out, and click Next.

    You will be presented only with the necessary options for your repository. If your project contains only one working copy, you will only have to select the branch to checkout. If your project doesn’t contain branches, you will only be given an option of working copies to checkout. If you project is a single working copy with no branches, this dialog will be skipped entirely.

  5. Select the location to store the working copy, and click Check Out.



2.當有修改時,在Source Control里面可以做點什么,我試了下commit,可以提交到本地,但是沒有提交到服務器,中間包括-1012錯誤,然后配置git用戶名跟郵箱。然后填寫版本注釋,然后就提交,看似提交成功,服務器上卻沒有。

iOS開發XCODE5 <wbr>SVN配置 <wbr>使用辦法

 

3.Push local changes:我點擊了試試,就出來下面這個,我有點疑惑,后來發現人家是

 push local changes to a remote git repository 

iOS開發XCODE5 <wbr>SVN配置 <wbr>使用辦法

然后我就有點懷疑,難道Xcode自帶的SVN的subversion類型不支持提交到服務器這個功能么。

然后看幫助文檔,有這么一句。

If you’re using Subversion, a commit operation copies the changes from selected files into the remote Subversion repository. Therefore, you must be connected to the repository before you can commit changes. (For details, see your repository administrator.)

搞了半天不懂 see your repository administrator是什么意思。翻譯出來是庫管理員。我只想說看他有個毛用。我自能默默自嘲英文差。

 

4.然后我就想着再繼續往下看。Updating or Pulling Changes from a Repository

如何更新和提交更改。然后就看到下面的內容。

Update your project with changes from the repository using the Source Control menu.

  • For a Git repository, choose Source Control > Pull.

  • For a Subversion repository, choose Source Control > Update.

  • For a project that contains both Git and Subversion repositories, choose Source Control > Update and Pull.

For projects with multiple repositories, select the ones you want to update.

Resolve differences by using the left and right buttons to specify which file’s contents to use.

After reconciling all differences, click Pull (Git) or Update (SVN) to complete the operation.

打開Source Control就沒有找到Pull和Update。本來就英文差,他媽的剛巧就認得這幾句,然后就此作罷。大牛莫要嘲笑我,還請告知我是哪里出了問題。

看了一個問答,XCODE5中怎么上傳到SVN服務器,老外給出的結論是:兩個辦法,一個是用svn client,客戶端軟件;另一個方法是命令行。One way is using an svn client. The one which is obviously available is the command line svn client.

http://stackoverflow.com/questions/18894195/xcode-5-export-project-to-svn-repository

 

但是事情不能不做,就在網上找了命令實驗了一下,盡可能寫的詳細點,下次看的時候好懂。隨便幫幫跟我一樣正在郁悶的人。

 

 

 

 

1.更改配置(不懂的話就直接跳過吧)

bogon:~ chenshuangchou$ open ~/.subversion/config

啟動配置文件,然后在配置文件中選擇要忽略的文件類型

找到 global-ignores 一行,去掉注釋,編輯成

global-ignores = build *~.nib *.so *.pbxuser *.mode *.perspective*

# global-ignores = *.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.a *.pyc *.pyo

 

找到 enable-auto-props = yes 把注釋去掉,在[auto-props] Section聲明以下文本文件

*.mode* = svn:mime-type=text/X-xcode

*.pbxuser = svn:mime-type=text/X-xcode

*.perspective* = svn:mime-type=text/X-xcode

*.pbxproj = svn:mime-type=text/X-xcode

 

2.import命令

首先將本地代碼import到版本庫

bogon:~ chenshuangchou$ svn import /Users/chenshuangchou/Desktop/BuickIOS/Buickhousekeeper  https://192.168.21.248:8443/svn/BuickIOS/ -m "initial import"

 

3.checkout命令

然后從版本庫checkout出來,這個目錄就相當於被激活,內部跟服務器地址關聯。

bogon:~ chenshuangchou$svn checkout https://192.168.21.248:8443/svn/BuickIOS/ /Users/chenshuangchou/Desktop/BuickIOS

 

 

4.add命令

當有新增的文件時用add指令,增加到版本庫,然后提交

svn add /Users/chenshuangchou/Desktop/BuickIOS/Buickhousekeeper/ViewControllers/CarViewController/FuelManageViewController/lastmouth_color1.png 

執行這條指令的前提是/Users/chenshuangchou/Desktop/BuickIOS/是從服務器checkout下來的目錄,也就是is a working copy

新增成功的話會有

A  (bin) Desktop/BuickIOS/Buickhousekeeper/ViewControllers/CarViewController/FuelManageViewController/lastmouth_color1.png

 

 

5.commit命令

提交內容到版本庫

bogon:~ chenshuangchou$ svn commit -m "添加了一個油耗柱狀圖" /Users/chenshuangchou/Desktop/BuickIOS/Buickhousekeeper/ViewControllers/CarViewController/FuelManageViewController/lastmouth_color1.png

提交到版本庫成功的話,

Adding  (bin) Desktop/BuickIOS/Buickhousekeeper/ViewControllers/CarViewController/FuelManageViewController/lastmouth_color1.png

Transmitting file data .

Committed revision 3.

 

 

 

6.update命令

更新版本庫到本地,更新指定目錄,svn update如果后面沒有目錄,默認將當前目錄以及子目錄下的所有文件都更新到最新版本。

bogon:~ chenshuangchou$ svn update /Users/chenshuangchou/Desktop/BuickIOS1

更新成功

Updating 'Desktop/BuickIOS1':

A   Desktop/BuickIOS1/Buickhousekeeper/ViewControllers/CarViewController/FuelManageViewController/lastmouth_color1.png

Updated to revision 3.

 

回退到版本2:    

bogon:~ chenshuangchou$ svn update -r 2 Desktop/BuickIOS1/

回退成功的話

Updating 'Desktop/BuickIOS1':

D   Desktop/BuickIOS1/Buickhousekeeper/ViewControllers/CarViewController/FuelManageViewController/lastmouth_color1.png

Updated to revision 2.

 

沖突

(更新,於版本庫同步。如果在提交的時候提示過期的話,是因為沖突,需要先update,修改文件 ,然后清除svn resolved ,最后再提交commit)

在提交時發生版本沖突會怎么樣

bogon:~ chenshuangchou$ svn commit -m "在delegate中加入了一句話" /Users/chenshuangchou/Desktop/BuickIOS/

Sending        Desktop/BuickIOS/.git/index

Sending        Desktop/BuickIOS/Buickhousekeeper/AppDelegate.h

Sending       Desktop/BuickIOS/Buickhousekeeper.xcodeproj/project.xcworkspace/xcuserdata/chenshuangchou.xcuserdatad/UserInterfaceState.xcuserstate

Transmitting file data ...

Committed revision 4.

bogon:~ chenshuangchou$ svn commit -m "在delegate中加入了一句不同的話" /Users/chenshuangchou/Desktop/BuickIOS1/

Sending        Desktop/BuickIOS1/.git/index

svn: E160042: Commit failed (details follow):

svn: E160042: File or directory '.git/index' is out of date; try updating

svn: E160024: resource out of date; try updating

out   of  date表示版本過期,可能是由於另外的開發者更新了服務器版本,而本地代碼與服務器沖突

 

遇到這種情況,應該先從服務器update一下,然后再提交

bogon:~ chenshuangchou$ svn update  Desktop/BuickIOS1/

Updating 'Desktop/BuickIOS1':

Conflict discovered in '/Users/chenshuangchou/Desktop/BuickIOS1/.git/index'.

Select: (p) postpone,

        (mf) mine-full, (tf) theirs-full,

        (s) show all options: 

在這里會有一個選擇,選擇(s)會顯示所有選項的所有注釋,如下

(s)  show all    - show this list

(e)  edit             - change merged file in an editor

(df) diff-full        - show all changes made to merged file

(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)

(tc) theirs-conflict  - accept their version for all conflicts (same)

(p) postpone  - mark the conflict to be resolved later。

(mf) mine-full  - accept my version of entire file (even non-conflicts)

(tf) theirs-full      - accept their version of entire file (same)

選擇一個之后會繼續顯示沖突點,直到完。而每一個點都會詢問怎么處理。

G   Desktop/BuickIOS1/Buickhousekeeper.xcodeproj/project.xcworkspace/xcuserdata/chenshuangchou.xcuserdatad/UserInterfaceState.xcuserstate

Conflict discovered in '/Users/chenshuangchou/Desktop/BuickIOS1/Buickhousekeeper/AppDelegate.h'.

Select: (p) postpone, (df) diff-full, (e) edit,

        (mc) mine-conflict, (tc) theirs-conflict,

        (s) show all options: tf

G    Desktop/BuickIOS1/Buickhousekeeper/AppDelegate.h

Updated to revision 4.

選擇tf之后,沖突點會被服務器上的代碼覆蓋,自己本地代碼會永久不見。最好先選擇postpone,確定之后再修改。

關於沖突,可以參考:http://www.logicaltrinkets.com/wordpress/?p=178

 

 

 

 

7.status命令

查看文件或者目錄狀態

svn status path (目錄下的文件和子目錄的狀態,正常狀態不顯示)

?:不在svn的控制中;M:內容被修改;C:發生沖突;A:預定加入到版本庫;K:被鎖定

svn status -v path 顯示所有文件的修改信息,在查看狀態的同時,顯示本地當前版本號,最后一次修改的版本號和修改人,分別在前

bogon:~ chenshuangchou$ svn status  Desktop/BuickIOS1/

M       Desktop/BuickIOS1/.git/index

?       Desktop/BuickIOS1/.git/objects/1c/7d8324a67dcd866bd0b4122b01b924a0e77128

?       Desktop/BuickIOS1/.git/objects/75/1826a72a4afd4b15faf73a0b6e4166d3bbec01

?       Desktop/BuickIOS1/.git/objects/a4/1c23190a65cda6a64a95bef22a9264ad64d90e

?       Desktop/BuickIOS1/.git/objects/b3/df5dbb592745d9744adf7a32ed2bb39370c78e

M       Desktop/BuickIOS1/Buickhousekeeper/AppDelegate.h

?       Desktop/BuickIOS1/Buickhousekeeper/lastmouth_color1.png

?       Desktop/BuickIOS1/Buickhousekeeper/lastmouth_color2.png

?       Desktop/BuickIOS1/Buickhousekeeper/lastmouth_color3.png

?       Desktop/BuickIOS1/Buickhousekeeper/lastmouth_color4.png

M       Desktop/BuickIOS1/Buickhousekeeper.xcodeproj/project.pbxproj

M      Desktop/BuickIOS1/Buickhousekeeper.xcodeproj/project.xcworkspace/xcuserdata/chenshuangchou.xcuserdatad/UserInterfaceState.xcuserstate

 

 

8.delete命令

svn delete path -m " delete test fle " 

刪除一個空白的文件夾:

bogon:~ chenshuangchou$ svn delete /Users/chenshuangchou/Desktop/BuickIOS/branches 

D         Desktop/BuickIOS/branches

顯示刪除成功

 

 

 

9.log命令

查看版本記錄,也叫日志

bogon:~ chenshuangchou$ svn log /Users/chenshuangchou/Desktop/BuickIOS

------------------------------------------------------------------------

r3 | chensc | 2013-10-31 11:34:03 +0800 (四, 31 10 2013) | 1 line

 

添加了一個油耗柱狀圖

------------------------------------------------------------------------

r2 | chensc | 2013-10-28 12:00:36 +0800 (一, 28 10 2013) | 1 line

 

initial import

------------------------------------------------------------------------

r1 | VisualSVN Server | 2013-06-28 17:40:29 +0800 (五, 28  6 2013) | 1 line

 

Initial structure.

 

只有兩個版本記錄,說明第二個版本和第三個版本未添加版本說明,也就是在執行指令時未添加-m  ,這個指令是添加注釋

 

 

10.diff命令

svn diff path(將修改的文件與基礎版本比較)

在上傳版本時,可能有自己版本與服務器版本不一致,需要查看具體代碼,這個命令就可以做到

svn diff -r m:n path

對版本m和版本n比較差異

在追溯版本問題時,這個命令也十分有用

bogon:~ chenshuangchou$ svn diff /Users/chenshuangchou/Desktop/BuickIOS1

--- /Users/chenshuangchou/Desktop/BuickIOS1/Buickhousekeeper/AppDelegate.h (revision 4)

+++ /Users/chenshuangchou/Desktop/BuickIOS1/Buickhousekeeper/AppDelegate.h (working copy)

@@ -6,6 +6,7 @@

 //  Copyright (c) 2013年 calinks. All rights reserved.

 //測試的很好

 

+

 #import

 #import "BMapKit.h"

 

@@ -15,7 +16,7 @@

 - (void)refreshIdeaMessage;

 

 - (void)refreshMaintainMessage;

-@end

+@end 

 

 

 

 

11.merge命令

將兩個版本之間的差異合並到當前文件

bogon:BuickIOS chenshuangchou$ svn merge -r 4:5 /Users/chenshuangchou/Desktop/BuickIOS/Buickhousekeeper/AppDelegate.h

一般會發生沖突,處理沖突

— /Users/chenshuangchou/Desktop/BuickIOS/Buickhousekeeper/svn-1FUb4k 四 10 31 15:36:15 2013

+++ /Users/chenshuangchou/Desktop/BuickIOS/.svn/tmp/AppDelegate.h.tmp 四 10 31 15:36:16 2013

@@ -4,8 +4,13 @@

 //  Copyright (c) 2013年 calinks. All rights reserved.

-//測試的很好

+<<<<<<< .working

+//測試一下

+=======

+//驗證版本差異合並

+>>>>>>> .merge-right.r5

 

 

 

 

12.ls命令

版本庫下的文件和目錄列表

svn list path顯示path目錄下的所有屬於版本庫的文件和目錄

bogon:BuickIOS chenshuangchou$ svn ls https://192.168.21.248:8443/svn/BuickIOS/

.git/

Buickhousekeeper/

Buickhousekeeper.xcodeproj/

DevOneSDK.framework/

branches/

tags/

trunk/

 

 

 

 

 

13.log命令

查看文件詳細信息

bogon:~ chenshuangchou$ svn info /Users/chenshuangchou/Desktop/BuickIOS/Buickhousekeeper/AppDelegate.h 

Path: Desktop/BuickIOS/Buickhousekeeper/AppDelegate.h

Name: AppDelegate.h

Working Copy Root Path: /Users/chenshuangchou/Desktop/BuickIOS

URL: https://chensc@192.168.21.248:8443/svn/BuickIOS/Buickhousekeeper/AppDelegate.h

Repository Root: https://chensc@192.168.21.248:8443/svn/BuickIOS

Repository UUID: 9a03820f-37b7-b94a-a594-74c58a350bc6

Revision: 4

Node Kind: file

Schedule: normal

Last Changed Author: chensc

Last Changed Rev: 4

Last Changed Date: 2013-10-31 14:04:51 +0800 (四, 31 10 2013)

Text Last Updated: 2013-10-31 14:02:51 +0800 (四, 31 10 2013)

Checksum: 83d8a08d317af33501b650517aa4033d5fe9f0d4

 

14.其它命令

svn mkdir : 創建納入版本控制下的新目錄。

用法: 1、mkdir PATH...

2、mkdir URL...

svn revert : 恢復原始未改變的工作副本文件 (恢復大部份的本地修改)。revert:

用法: revert PATH...

注意: 本子命令不會存取網絡,並且會解除沖突的狀況。但是它不會恢復

被刪除的目錄

svn switch (sw): 更新工作副本至不同的URL。

用法: 1、switch URL [PATH]

     2、switch --relocate FROM TO [PATH...]

svn resolved: 移除工作副本的目錄或文件的“沖突”狀態。

用法: resolved PATH...

注意: 本子命令不會依語法來解決沖突或是移除沖突標記;它只是移除沖突的

相關文件,然后讓 PATH 可以再次提交。

svn cat 輸出指定文件或URL的內容。

svn cat 目標[@版本]...如果指定了版本,將從指定的版本開始查找。

svn cat -r PREV filename > filename (PREV 是上一版本,也可以寫具體版本號,這樣輸出結果是可以提交的)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM