版本控制系統

日期:2015/7/2
主題:版本控制系統(VCS, Version Control System)

種類:

版本控制系統的種類:

  1. 本地端版本控制
  2. 集中式版本控制
  3. 分散式版本控制

分散式版本控制

  • 可離線編輯,每台主機都有版本庫(Repo)

指令:

環境設定

  • 設定全域名稱和信箱
      % git config --global user.name "<使用者名字>"
      % git config --global user.email "<電子信箱>"
    
  • 設定~/.gitconfig
    .gitignore:哪些檔案不想進行版本控制
    

基礎指令

  1. 建立版本庫
    % git init [<directory>]
    
  2. 新增README.md

    % touch README.md
    
  3. 查看狀態

    % git status
    
  4. 把檔案加入版本控制

    % git add <file> ...
    
  5. 確認版本

    % git commit
    
  6. 查看差異

    % git diff //查看workDir與Repo的差異
    % git diff --cached //查看stag與Repo差異
    

git狀態圖示

git狀態圖示

檔案狀態與還原

  1. 查看log檔

    % git log
    
  2. 切換到檔案

    % git checkout 123456  //切換到某個檔案
    % git checkout master  //切換到master
    
  3. 設定tag

    % git checkout 123456
    % git tag <TagName>          //設定tag
    % git tag checkout <TagName> //切換到某個tag檔案
    
  4. 還原之前狀態

    % git reset <TagName>    //還原到某個tag,在它後面的修改會被刪除。
    % git revert  <TagName>  //將某個tag變成為最新狀態(在它後面的修改不會被刪除)
    

分支(Branch)

  1. 查看所有分支
    % git branch
    
  2. 新增一個分支

    % git branch <branch name>
    
  3. 切換到某個分支

    % git checkout <branch name>
    
  4. 合併

    % git merge <branch name>
    在master branch下
    % git merge test  //將test branch 合併至master branch
    
  5. 刪除分支

    % git branch -d <branch name> //刪除已merge過的分支
    % git branch -D <branch name> //刪除尚未merger過的分支
    

遠端線上版本庫(Remote Repo)

  1. 查看所有遠端版本庫
    % git remote
    % git remote -v
    
  2. 新增遠端版本庫

    % git remote add <name> <remote_UL>
    % git remote add origin https://github.com/wssu/test20150703.git  //以https方式
    % git remote add origin2 [email protected]:wssu/test20150703.git  //以ssh方式
    
  3. 上傳檔案至遠端版本庫

    % git push -a origin <branch name>  //branch未建立則自動新增分支
    % git push -a origin master  //push到遠端的master分支
    
  4. 至遠端版本庫下載檔案

    % git pull
    % git pull = git fetch + git merge
    % git pull origin master   //下載origin遠端版本庫的master分支
    
  5. 以https連線,設定記住帳號一小時

    % git config --global credential.helper cache
    % git config --global credential.helper "cache --timeout=3600"
    

Clone別人的Repo

  1. 以SSH方式
    % git clone [email protected]:example/project.git
    
  2. 以https方式
    % git clone https://github.com/example/project.git
    

自架VCS的憑證問題

  • 跳過憑證檢查
    % git config --global http.sslVerify false
    

results matching ""

    No results matching ""