PHPStorm在CentOS中的版本控制使用指南(以Git為例)
在CentOS系統中,首先需要安裝Git工具(若未安裝)。打開終端,執行以下命令:
sudo yum update -y && sudo yum install git -y
安裝完成后,通過git --version
驗證是否安裝成功(顯示Git版本號即為成功)。
為Git提交記錄關聯作者信息,執行以下命令(替換為你的實際姓名和郵箱):
git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"
可選:配置默認文本編輯器(如nano):
git config --global core.editor nano
File > Settings
(或使用快捷鍵Ctrl+Alt+S
)。Version Control
,選擇Git
。在Path to Git executable
輸入框中,填寫Git可執行文件的路徑(通常為/usr/bin/git
)。Test
按鈕,若彈出“Git executable is valid”提示,說明配置成功,點擊OK
保存。有兩種方式初始化倉庫:
File > Open
,選擇項目文件夾。右鍵點擊項目根目錄,選擇VCS > Enable Version Control Integration
,在彈出的對話框中選擇Git
,點擊OK
。此時項目根目錄會生成.git
隱藏文件夾(版本控制信息存儲位置)。VCS > Checkout from Version Control > Git
,輸入遠程倉庫URL(如GitHub、GitLab的倉庫地址),選擇本地克隆路徑,點擊Clone
即可將遠程倉庫復制到本地。右鍵點擊需要版本控制的文件(或文件夾),選擇Git > Add
,文件會進入暫存區(等待提交)。也可通過頂部菜單VCS > Git > Add
批量添加。
點擊底部狀態欄的Version Control
面板(或按Alt+9
),查看未提交的更改。點擊Commit
按鈕(或右鍵選擇Git > Commit Directory
),輸入提交信息(如“修復登錄bug”),點擊Commit
完成提交(提交后更改會保存到本地倉庫)。
Version Control
面板中的Push
按鈕(或頂部菜單VCS > Git > Repository > Push
),選擇遠程倉庫(如origin
)和分支(如main
),點擊Push
將本地提交推送到遠程倉庫。Version Control
面板中的Pull
按鈕(或頂部菜單VCS > Git > Repository > Pull
),選擇遠程倉庫和分支,點擊Pull
獲取遠程最新更改并合并到本地。Version Control
面板中的Git > Branches
,選擇New Branch
,輸入分支名稱(如feature/login
),點擊Create
。Git > Branches
中選擇目標分支,點擊Checkout
即可切換。main
),點擊Git > Branches > Merge Changes
,選擇要合并的分支(如feature/login
),點擊Merge
完成合并。若需使用SVN而非Git,需先安裝SVN插件:
File > Settings > Plugins
,搜索“Subversion Integration”,點擊Install
并重啟PHPStorm。File > Settings > Version Control > Subversion
,在Path to Subversion executable
中輸入SVN可執行文件路徑(如/usr/bin/svn
),點擊Test
驗證連接。VCS > Enable Version Control Integration
,選擇Subversion
即可。