Git使用筆記

出自GaryLee
跳轉到: 導覽, 搜尋

目錄

建立Repository

  • 建立一個空的repository。透過--bare參數會建立一個沒有副本內容的repository。也就是說你在這個目錄下面只會看到git的管理檔案,不會看到你commit的文件。這適合用於建立大家共用的remote git repository。
mkdir xxx.git
cd xxx.git
git init --bare
  • 建立一個空的repository,並且在裡面進行工作。
mkdir xxx
cd xxx
git init

取得遠端的Repository

  • 複製一份遠端的Repository
git clone git://git.server.somewhere/xxx.git
  • 複製一份遠端的Repository。使用pull會自動進行merge的動作。使用fetch則需要手動進行checkout與merge。
git pull git://git.server.somewhere/xxx.git
git fetch git://git.server.somewhere/xxx.git 

tag的處理

  • 建立一個local tag
git tag -a -m "commit message" <tag_name>
  • 將tag更新到遠端的git repository。
git push --tags 

Branch的處理

  • 列出當前的branch
git branch -l

新增,刪除與移動檔案

  • 新增檔案
git add filename
git add foldername
  • 刪除檔案
git rm filename
git rm foldername
  • 移動或更名檔案
git mv orig_filename new_filename
git mv orig_foldername new_foldername

分支

  • 列出分支 (-r參數會列出遠端的分支, -a參數會列出所有local與遠端的分支)
git branch
git branch -r
git branch -a
  • 新增本地分支
git branch <branch name>
git
  • 更名本地分支
git branch <branch name>
git branch -m <orignal branch name> <new branch name>
  • 刪除本地分支
git branch -d <branch name>
  • 遠端分支(先建立本地分之後,再push所有東西到遠端去)
git branch <branch name>
git checkout <branch name>
git push --all
  • 讓目前的分支追蹤遠端分支
git branch -t origin/<branch name>

commit

  • commit檔案(-a 參數會commit所有修改過的檔案)
git commit -m "commit message"
git commit -a -m "commit message"

參考

  • [TortoiseGit] : 與Windows檔案管理員整合最好的Git client。
  • [Msysgit] : Windows版本的git client。免裝Cygwin。
個人工具