svn常用命令列和批處理

shwenwen發表於2010-07-09
在進行大量svn更新和多個工程聯合編譯時,如果是對你來說是一件經常重複做的事情,譬如更新程式碼編譯版本;更新程式碼,編譯版本並升級之類的重複性很高, 枯燥而且容易出錯的事情,使用批處理來統一管理和處理將大大簡化工作流程,使編版本,升級成為一件快樂的事情,想一下,要升級了,準備工作做好後,執行下 批處理,“嘩嘩”就跟你有條不紊的做好了,多麼愜意的一件事情,而且不可能產生人為原因的錯誤,要統一批處理化,那就自然要熟悉各種工具的命令列了,首先 來看看svn的,嘿嘿[@more@]
svn常用命令列和批處理

svn的命令列的詳細使用,這篇文章講得比較詳細:,但是一般開發人員用不了這麼多,下面簡單介紹我常用的5-6個:

1、help,檢視有你當前的svn版本支援哪些命令,在控制檯下輸入svn help,回車,顯示如下:

  1. usage: svn [options] [args]
  2. Subversion command-line client, version 1.6.1.
  3. Type 'svn help ' for help on a specific subcommand.
  4. Type 'svn --version' to see the program version and RA modules
  5. or 'svn --version --quiet' to see just the version number.
  6. Most subcommands take file and/or directory arguments, recursing
  7. on the directories. If no arguments are supplied to such a
  8. command, it recurses on the current directory (inclusive) by default.
  9. Available subcommands:
  10. add
  11. blame (praise, annotate, ann)
  12. cat
  13. changelist (cl)
  14. checkout (co)
  15. cleanup
  16. commit (ci)
  17. copy (cp)
  18. delete (del, remove, rm)
  19. diff (di)
  20. export
  21. help (?, h)
  22. import
  23. info
  24. list (ls)
  25. lock
  26. log
  27. merge
  28. mergeinfo
  29. mkdir
  30. move (mv, rename, ren)
  31. propdel (pdel, pd)
  32. propedit (pedit, pe)
  33. propget (pget, pg)
  34. proplist (plist, pl)
  35. propset (pset, ps)
  36. resolve
  37. resolved
  38. revert
  39. status (stat, st)
  40. switch (sw)
  41. unlock
  42. update (up)
  43. Subversion is a tool for version control.
  44. For additional information, see http://subversion.tigris.org/
usage: svn [options] [args] Subversion command-line client, version 1.6.1. Type 'svn help ' for help on a specific subcommand. Type 'svn --version' to see the program version and RA modules or 'svn --version --quiet' to see just the version number. Most subcommands take file and/or directory arguments, recursing on the directories. If no arguments are supplied to such a command, it recurses on the current directory (inclusive) by default. Available subcommands: add blame (praise, annotate, ann) cat changelist (cl) checkout (co) cleanup commit (ci) copy (cp) delete (del, remove, rm) diff (di) export help (?, h) import info list (ls) lock log merge mergeinfo mkdir move (mv, rename, ren) propdel (pdel, pd) propedit (pedit, pe) propget (pget, pg) proplist (plist, pl) propset (pset, ps) resolve resolved revert status (stat, st) switch (sw) unlock update (up) Subversion is a tool for version control. For additional information, see

如果你想檢視某個具體命令的使用,直接svn help [command]即可,譬如想看看checkout的用法:svn help checkout,顯示內容比較多,自己去看看吧。

2、update的用法,這個應該是用得最多的一個命令(或者叫操作吧)了,使用很簡單,你要更新哪個目錄,就先進到那個目錄,然後在那個目錄下執行 svn update。譬如你要更新目錄:H:QQDrPrjAPPLightDogQQDoctor3.2Output。

  1. @echo off
  2. set svnpath="H:QQDrPrjAPPLightDogQQDoctor3.2Output"
  3. h:
  4. cd %svnpath%
  5. svn update
  6. pause
@echo off set svnpath="H:QQDrPrjAPPLightDogQQDoctor3.2Output" h: cd %svnpath% svn update pause

3、checkout的使用方法,checkout就是把程式碼或者其他資料從伺服器上下載到本地的意思,所以是要指明伺服器的地址的,首先你也要進到一個目的資料夾(就是你要把程式碼下載到哪兒),然後就可以執行svn checkout 了。下面一段指令碼是將typedef資料夾下的所有檔案包括typedef資料夾更新到h盤根目錄下。(注意,執行之後,如果是第一次執行很可能向你詢問使用者名稱和密碼等資訊)

  1. @echo off
  2. set svnpath="H:"
  3. h:
  4. cd %svnpath%
  5. svn checkout https://xx.x.xx.xx:xxxx/svn/ims/APP/Output/TypeDef
  6. pause
@echo off set svnpath="H:" h: cd %svnpath% svn checkout pause

4、commit提交程式碼到伺服器上,和update的使用方法類似,但是要記錄一個log資訊[加上 -m ""],svn commit -m ""。或者註冊環境變數SVN_EDITOR也可以(譬如註冊一個環境變數名為SVN_EDITOR,值為notepad.exe的環境變數),這樣的話 直接svn commit也可以,如果你既沒有加-m ""又沒有註冊SVN_EDITOR環境變數,那麼執行此命令時會報如下的錯誤:

  1. svn: Commit failed (details follow):
  2. svn: Could not use external editor to fetch log message; consider setting the $S
  3. VN_EDITOR environment variable or using the --message (-m) or --file (-F) option
  4. s
  5. svn: None of the environment variables SVN_EDITOR, VISUAL or EDITOR are set, and
  6. no 'editor-cmd' run-time configuration option was found
svn: Commit failed (details follow): svn: Could not use external editor to fetch log message; consider setting the $S VN_EDITOR environment variable or using the --message (-m) or --file (-F) option s svn: None of the environment variables SVN_EDITOR, VISUAL or EDITOR are set, and no 'editor-cmd' run-time configuration option was found

5、add程式碼或者檔案到伺服器,這個命令其實比較少使用命令列進行,嘿嘿!執行時要確保當前目錄下有你要增加的檔案或者資料夾,直接執行 svn add myfile.txt 或者 svn add myforder,例如:下面是將h盤下Documents目錄下的engine資料夾增加到svn中(前提是Documents是一個svn的工作目 錄,否則會執行失敗)。

  1. @echo off
  2. set svnpath="H:Documents"
  3. h:
  4. cd %svnpath%
  5. svn add engine
  6. pause
@echo off set svnpath="H:Documents" h: cd %svnpath% svn add engine pause

6、cleanup清理命令,能夠清理某個目錄下的一些執行失敗的事務,和update的用法類似。

7、log檢視日誌,可以檢視某個目錄或者檔案的日誌資訊,這個可以在執行一批命令後再檢查下是否執行正確。用法很簡單,類似add命令,下面是檢視Documents下面myfile.txt檔案的日誌。

  1. @echo off
  2. set svnpath="H:Documents"
  3. h:
  4. cd %svnpath%
  5. svn log "myfile.txt"
  6. pause
@echo off set svnpath="H:Documents" h: cd %svnpath% svn log "myfile.txt" pause

svn的命令就介紹到這裡了,可以和vc的命令汗聯合起來,這樣就可以直接更新編譯了,如下:

  1. @echo off
  2. @echo 請使用svn更新檔案
  3. set svnpath="h:myprjVulInfoDataBase"
  4. h:
  5. cd %svnpath%
  6. svn update
  7. explorer.exe "h:myprjVulInfoDataBase"
  8. pause
  9. @echo 編譯
  10. msdev "h:myprjVulInfoDataBaseVulChkmyprj.dsw" /MAKE "TSVulChk - Win32 Release"
  11. pause
@echo off @echo 請使用svn更新檔案 set svnpath="h:myprjVulInfoDataBase" h: cd %svnpath% svn update explorer.exe "h:myprjVulInfoDataBase" pause @echo 編譯 msdev "h:myprjVulInfoDataBaseVulChkmyprj.dsw" /MAKE "TSVulChk - Win32 Release" pause

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/143526/viewspace-1035102/,如需轉載,請註明出處,否則將追究法律責任。