1. 程式人生 > 實用技巧 >git官方文件

git官方文件

建立

  克隆一個外部倉庫
  git clone ssh://user&mail.com/repo.git
  建立一個新的本地版本庫
  git init

本地改變

  檢視在工作目錄的被修改檔案
  git status
  改變去暫存的檔案
  git diff
  新增所有的當前修改去下一次提交commit
  git add .
  新增一些改變在<file>去下一次提交commit
  git add -p <file>
  提交所有的本地修改在暫存區的檔案
  git commit -a
  提交先前暫存的改變
  git commit 
  改變這個上一次的提交
  git commit --amend

提交歷史

  展示所有的提交,從最新的開始展示
  git log
  顯示特定檔案隨時間的變化 
  git log -p <file>
  誰改變了什麼和當在檔案中
  git blame <file>

分支和標記

  列出所有現有的分支
  git branch -av
  切換頭分支
  git checkout <branch>
  建立一個新的分支基於你當前的HEAD
  git branch <new-branch>
  建立一個新的跟蹤分支基於一個遠端的分支
  git checkout --track <remote/branch>
  刪除一個本地分支
  git branch -d <branch>
  標記當前的提交一個標籤
  git tag <tag-name>

更新和發行

  列出所有的當前配置過的遠端
  git remote -v
  展示關於這個遠端的資訊
  git remote show <remote>
  新增一個遠端倉庫,命名<remote>
  git remote add <shortname> <url>
  下載所有的改變從遠端,但當時不用合併進入頭部
  git fetch <remote>
  下載改變和目錄合併/整合進HEAD
  git pull <remote> <branch>
  發行本地改變在一個遠端
  git push <remote> <branch>
  刪除一個遠端分支
  git branch -dr <remote / branch>
  發行你的標記
  git push --tags

合併和變基

  合併<branch>進入你當前的頭
  git merge <branch>
  
  把你現在的頭放在<branch>
  不要將已釋出的提交還原!
  git rebase <branch>
  
  abort rebase
  git rebase --abort
  
  Continue a rebase after resolving conflicts
  $ git rebase --continue

  Use your configured merge tool to 
  solve conflicts

  $ git mergetool
  Use your editor to manually solve conflicts 

  and (after resolving) mark file as resolved
  $ git add <resolved-file>
  $ git rm <resolved-file>     

UNDO

  Discard all local changes in your working 
  directory
  $ git reset --hard HEAD

  Discard local changes in a specific file
  $ git checkout HEAD <file>

  Revert a commit (by producing a new commit 
  with contrary changes)
  $ git revert <commit>

  Reset your HEAD pointer to a previous commit
  …and discard all changes since then
  $ git reset --hard <commit>

  …and preserve all changes as unstaged 
  changes
  $ git reset <commit>

  …and preserve uncommitted local changes
  $ git reset --keep <commit>