獲取svn倉庫
首先要知道svn地址,然後通過如下命令獲取svn倉庫:
svn checkout svn://svn_resp_url
或者簡寫:
svn co svn://svn_resp_url
SVN提交更新
SVN在提交更新的時候很簡單:
svn commit -m "commit log content"
簡寫方法爲:
svn ci -m "commit log content"
如果有新添加的文件需要先運行:
svn add file_path/file_name
如果有新刪除的文件需要:
svn rm file_path/filename
svn獲取最新版本
如果長時間沒動,需要獲取服務器最新版本:
svn update
放棄本地修改
如果要放棄某個文件的本地修改(還沒有commit):
svn revert foo.c //foo.c是文件路徑+名字
如果要放棄所有修改:
svn revert --depth=infinity
已經commit
如果代碼已經commit結束了,那麼需要使用merge的方式來對代碼進行回滾。
首先使用:
svn log //查看你要回滾到哪個版本
然後:
svn update //獲取最新版本 得到版本號
svn merge -r 150:140 . //回滾代碼從150回滾到140
svn commit -m "Rolled back to r140" //提交合並結果版本+1
這樣就可以了。
打tag
如果當前已經開發一個版本結束,需要保存,這個時候不是記住版本號,而已打tag,這樣就算作一個正式版本了。命令就是:
svn copy http://svn_server/xxx_repository/trunk http://svn_server/xxx_repository/tags/release-1.0 -m "1.0 released"
如果要刪除某個tag:
svn rm http://svn_server/xxx_repository/tags/release-1.0
出現衝突
如果是同時多個人協作的話,或者自己在兩個電腦上改了同一個地方的代碼,是有可能出現衝突的(conflict),這個時候需要修改衝突。
在查看文件的時候可以看到:
<<<<<<< .mine
your code here
=======
other code here
>>>>>> .r1234
手工選擇你想要的代碼,然後使用:
svn reslove --accept working conflict_file.c
這裏在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.
mine-full (mf)
Resolve conflicted files by preserving all local modifications and discarding all changes fetched from the server during the operation which caused the conflict.
theirs-full (tf)
Resolve conflicted files by discarding all local modifications and integrating all changes fetched from the server during the operation which caused the conflict.
mine-conflict (mc)
Resolve conflicted files by preferring local modifications over the changes fetched from the server in conflicting regions of each file's content.
theirs-conflict (tc)
Resolve conflicted files by preferring the changes fetched from the server over local modifications in conflicting regions of each file's content.
選擇對應的選項就好了。
這個命令結束後,會自動刪除衝突的臨時文件conflict_file.c.mine conflict_file.c.r123
這種文件。