Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> 關於 Linux

Linux SVN 操作實戰指南:Checkout、Add、Commit、Lock/Unlock 完整範例

編輯:關於 Linux

Subversion (SVN) 是廣泛使用的版本控制系統。本文整理 Linux 下 SVN 常用操作指令與實戰範例,涵蓋檢出、新增檔案、提交變更、加鎖/解鎖、更新、解決衝突等核心流程,適合開發者快速查閱。

1. 檢出版本庫

svn checkout svn://192.168.1.1/pro/domain
# 縮寫:svn co svn://192.168.1.1/pro/domain
# 指定版本:svn co -r 123 svn://...

2. 新增檔案至版本控制

svn add test.php              # 單一檔案
svn add *.php                 # 當前目錄所有 php
svn add --force .             # 遞歸新增所有未受控檔案

3. 提交變更

svn commit -m "add test file for my test" test.php
# 縮寫:svn ci -m "msg" [PATH]
# 保持鎖:svn ci --no-unlock -m "msg" test.php

4. 加鎖 / 解鎖(獨佔編輯)

svn lock -m "lock test file" test.php
# 強制加鎖:svn lock --force -m "msg" test.php

svn unlock test.php

5. 更新與衝突處理

svn update                    # 更新工作副本
svn update -r 100             # 更新至指定版本

# 衝突發生時:
svn status                    # 顯示 C 衝突檔案
# 手工編輯衝突檔(尋找 <<<<<<< ======= >>>>>>> 標記)
svn resolved test.php         # 標記衝突已解決
svn commit -m "resolve conflict" test.php

6. 查看狀態、差異、日誌

svn status                    # 工作副本狀態
svn diff test.php             # 與基底版本差異
svn diff -r 100:101 test.php  # 版本間差異
svn log                       # 提交日誌
svn log -l 10                 # 最近 10 筆
svn info                      # 版本庫資訊

7. 分支與合併(基礎)

# 建立分支
svn copy svn://server/trunk svn://server/branches/feature-x -m "create branch"

# 切換至分支
svn switch svn://server/branches/feature-x

# 合併主幹變更至分支
svn merge svn://server/trunk

# 合併分支回主幹(reintegrate)
svn merge --reintegrate svn://server/branches/feature-x

SVN 操作示意圖

實用技巧

  • svn blame file:顯示每行最後修改者與版本。
  • svn externals:掛載外部版本庫目錄。
  • svn export:導出乾淨程式碼(無 .svn 目錄)。
  • 設定 ~/.subversion/config 啟用 auto-props 自動設定 svn:keywords、svn:eol-style。
Copyright © Windows教程網 All Rights Reserved