簡明 Git 命令速查表(中文版)

來源:互聯網
上載者:User

簡明 Git 命令速查表(中文版)

 

建立

複製一個已建立的倉庫:

  1. $ git clone ssh://[email protected]/repo.git

建立一個新的本地倉庫:

  1. $ git init

 

本地修改

顯示工作路徑下已修改的檔案:

  1. $ git status

顯示與上次提交版本檔案的不同:

  1. $ git diff

把當前所有修改添加到下次提交中:

  1. $ git add

把對某個檔案的修改添加到下次提交中:

  1. $ git add -p <file>

提交本地的所有修改:

  1. $ git commit -a

提交之前已標記的變化:

  1. $ git commit

附加訊息提交:

  1. $ git commit -m 'message here'

提交,並將提交時間設定為之前的某個日期:

  1. git commit --date="`date --date='n day ago'`"-am "Commit Message"

修改上次提交
請勿修改發行的提交記錄!

  1. $ git commit --amend

把當前分支中未提交的修改移動到其他分支

  1. git stash
  2. git checkout branch2
  3. git stash pop

 

搜尋

從目前的目錄的所有檔案中尋找常值內容:

  1. $ git grep "Hello"

在某一版本中搜尋文本:

  1. $ git grep "Hello" v2.5

 

提交曆史

從最新提交開始,顯示所有的提交記錄(顯示hash, 作者資訊,提交的標題和時間):

  1. $ git log

顯示所有提交(僅顯示提交的hash和message):

  1. $ git log --oneline

顯示某個使用者的所有提交:

  1. $ git log --author="username"

顯示某個檔案的所有修改:

  1. $ git log -p <file>

誰,在什麼時間,修改了檔案的什麼內容:

  1. $ git blame <file>

 

分支與標籤

列出所有的分支:

  1. $ git branch

切換分支:

  1. $ git checkout <branch>

建立並切換到新分支:

  1. $ git checkout -b <branch>

基於當前分支建立新分支:

  1. $ git branch <new-branch>

基於遠程分支建立新的可追溯的分支:

  1. $ git branch --track <new-branch><remote-branch>

刪除本地分支:

  1. $ git branch -d <branch>

給目前的版本打標籤:

  1. $ git tag <tag-name>

 

更新與發布

列出當前配置的遠程端:

  1. $ git remote -v

顯示遠程端的資訊:

  1. $ git remote show <remote>

添加新的遠程端:

  1. $ git remote add <remote><url>

下載遠程端版本,但不合并到HEAD中:

  1. $ git fetch <remote>

下載遠程端版本,並自動與HEAD版本合并:

  1. $ git remote pull <remote><url>

將遠程端版本合并到本地版本中:

  1. $ git pull origin master

將本地版本發布到遠程端:

  1. $ git push remote <remote><branch>

刪除遠程端分支:

  1. $ git push <remote>:<branch>(since Git v1.5.0)
  2. git push <remote>--delete<branch>(since Git v1.7.0)

發布標籤:

  1. $ git push --tags

 

合并與重設

將分支合并到當前HEAD中:

  1. $ git merge <branch>

將當前HEAD版本重設到分支中:
請勿重設發行的提交!

  1. $ git rebase <branch>

退出重設:

  1. $ git rebase --abort

解決衝突後繼續重設:

  1. $ git rebase --continue

使用配置好的merge tool 解決衝突:

  1. $ git mergetool

在編輯器中手動解決衝突後,標記檔案為已解決衝突

  1. $ git add <resolved-file>
  1. $ git rm <resolved-file>

 

撤銷

放棄工作目錄下的所有修改:

  1. $ git reset --hard HEAD

移除緩衝區的所有檔案(i.e. 撤銷上次git add):

  1. $ git reset HEAD

放棄某個檔案的所有本地修改:

  1. $ git checkout HEAD <file>

重設一個提交(通過建立一個截然不同的新提交)

  1. $ git revert <commit>

將HEAD重設到指定的版本��並拋棄該版本之後的所有修改:

  1. $ git reset --hard <commit>

將HEAD重設到上一次提交的版本,並將之後的修改標記為未添加到緩衝區的修改:

  1. $ git reset <commit>

將HEAD重設到上一次提交的版本,並保留未提交的本地修改:

  1. $ git reset --keep <commit>

GitHub 教程系列文章: 

GitHub 使用教程圖文詳解   

Git 標籤管理詳解  

Git 分支管理詳解  

Git 遠程倉庫詳解  

Git 本地倉庫(Repository)詳解  

Git 伺服器搭建與用戶端安裝   

Git 概述  

分享實用的GitHub 使用教程  

Git 的詳細介紹:請點這裡
Git 的:請點這裡

本文永久更新連結地址:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.