轉載http://blog.sina.com.cn/s/blog_68661bd80101phpy.htmlphp
這兩天響應老闆要求,把全部代碼放到公司的SVN服務器上,按照個人想法確定是就蘋果組建一個服務器,而後內部版本控制,自帶的Xcode就有這個功能,以前也這麼作過,可是xcode4.X系列SVN仍是很好用,自從升級到Xcode5以後還沒弄過。今天試了一下午仍是沒徹底明白,眼看弄不出來,就直接用命令行了,不過一些簡單的東西仍是試出來了。html
1.如何使用Xcode5 SVN從公司服務器 check out項目git
Choose Source Control > Check Out.xcode
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.網絡
If Xcode is unable to automatically identify the trunk and branches, use the browser window to select the correct project location, and click Next.ide
In the Checkout window, select the branches and working copies to check out, and click Next.wordpress
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.svn
Select the location to store the working copy, and click Check Out.post
2.當有修改時,在Source Control裏面能夠作點什麼,我試了下commit,能夠提交到本地,可是沒有提交到服務器,中間包括-1012錯誤,而後配置git用戶名跟郵箱。而後填寫版本註釋,而後就提交,看似提交成功,服務器上卻沒有。
3.Push local changes:我點擊了試試,就出來下面這個,我有點疑惑,後來發現人家是
而後我就有點懷疑,難道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 : 建立歸入版本控制下的新目錄。
用法: 一、mkdir PATH...
二、mkdir URL...
svn revert : 恢復原始未改變的工做副本文件 (恢復大部份的本地修改)。revert:
用法: revert PATH...
注意: 本子命令不會存取網絡,而且會解除衝突的情況。可是它不會恢復
被刪除的目錄
svn switch (sw): 更新工做副本至不一樣的URL。
用法: 一、switch URL [PATH]
二、switch --relocate FROM TO [PATH...]
svn resolved: 移除工做副本的目錄或文件的「衝突」狀態。
用法: resolved PATH...
注意: 本子命令不會依語法來解決衝突或是移除衝突標記;它只是移除衝突的
相關文件,而後讓 PATH 能夠再次提交。
svn cat 輸出指定文件或URL的內容。
svn cat 目標[@版本]...若是指定了版本,將從指定的版本開始查找。
svn cat -r PREV filename > filename (PREV 是上一版本,也能夠寫具體版本號,這樣輸出結果是能夠提交的)