一、 Git 常用命令速查
git branch 查看本地所有分支
git status 查看當前狀態
git commit 提交
git branch -a 查看所有的分支
git branch -r 查看遠程所有分支
git commit -am "init" 提交並且加注釋
git remote add origin git@192.168.1.119:ndshow
git push origin master 將文件給推到服務器上
git remote show origin 顯示遠程庫origin里的資源
git push origin master:develop
git push origin master:hb-dev 將本地庫與服務器上的庫進行關聯
git checkout --track origin/dev 切換到遠程dev分支
git branch -D master develop 刪除本地庫develop
git checkout -b dev 建立一個新的本地分支dev
git merge origin/dev 將分支dev與當前分支進行合並
git checkout dev 切換到本地dev分支
git remote show 查看遠程庫
git add .
git rm 文件名(包括路徑) 從git中刪除指定文件
git clone git://github.com/schacon/grit.git 從服務器上將代碼給拉下來
git config --list 看所有用戶
git ls-files 看已經被提交的
git rm [file name] 刪除一個文件
git commit -a 提交當前repos的所有的改變
git add [file name] 添加一個文件到git index
git commit -v 當你用-v參數的時候可以看commit的差異
git commit -m "This is the message describing the commit" 添加commit信息
git commit -a -a是代表add,把所有的change加到git index里然后再commit
git commit -a -v 一般提交命令
git log 看你commit的日志
git diff 查看尚未暫存的更新
git rm a.a 移除文件(從暫存區和工作區中刪除)
git rm --cached a.a 移除文件(只從暫存區中刪除)
git commit -m "remove" 移除文件(從Git中刪除)
git rm -f a.a 強行移除修改后文件(從暫存區和工作區中刪除)
git diff --cached 或 $ git diff --staged 查看尚未提交的更新
git stash push 將文件給push到一個臨時空間中
git stash pop 將文件從臨時空間pop下來
---------------------------------------------------------
git remote add origin git@github.com:username/Hello-World.git
git push origin master 將本地項目給提交到服務器中
-----------------------------------------------------------
git pull 本地與服務器端同步
-----------------------------------------------------------------
git push (遠程倉庫名) (分支名) 將本地分支推送到服務器上去。
git push origin serverfix:awesomebranch
------------------------------------------------------------------
git fetch 相當於是從遠程獲取最新版本到本地,不會自動merge
git commit -a -m "log_message" (-a是提交所有改動,-m是加入log信息) 本地修改同步至服務器端 :
git branch branch_0.1 master 從主分支master創建branch_0.1分支
git branch -m branch_0.1 branch_1.0 將branch_0.1重命名為branch_1.0
git checkout branch_1.0/master 切換到branch_1.0/master分支
du -hs
git branch 刪除遠程branch
git push origin :branch_remote_name
git branch -r -d branch_remote_name
-----------------------------------------------------------
初始化版本庫,並提交到遠程服務器端
mkdir WebApp
cd WebApp
git init 本地初始化
touch README
git add README 添加文件
git commit -m 'first commit'
git remote add origin git@github.com:daixu/WebApp.git
增加一個遠程服務器端
上面的命令會增加URL地址為'git@github.com:daixu/WebApp.git',名稱為origin的遠程服務器庫,以后提交代碼的時候只需要使用 origin別名即可
二、 Git 命令速查表
1、常用的Git命令
命令
簡要說明
git add
添加至暫存區
git add–interactive
交互式添加
git apply
應用補丁
git am
應用郵件格式補丁
git annotate
同義詞,等同於 git blame
git archive
文件歸檔打包
git bisect
二分查找
git blame
文件逐行追溯
git branch
分支管理
git cat-file
版本庫對象研究工具
git checkout
檢出到工作區、切換或創建分支
git cherry-pick
提交揀選
git citool
圖形化提交,相當於 git gui 命令
git clean
清除工作區未跟蹤文件
git clone
克隆版本庫
git commit
提交
git config
查詢和修改配置
git describe
通過里程碑直觀地顯示提交ID
git diff
差異比較
git difftool
調用圖形化差異比較工具
git fetch
獲取遠程版本庫的提交
git format-patch
創建郵件格式的補丁文件。參見 git am 命令
git grep
文件內容搜索定位工具
git gui
基於Tcl/Tk的圖形化工具,側重提交等操作
git help
幫助
git init
版本庫初始化
git init-db*
同義詞,等同於 git init
git log
顯示提交日志
git merge
分支合並
git mergetool
圖形化沖突解決
git mv
重命名
git pull
拉回遠程版本庫的提交
git push
推送至遠程版本庫
git rebase
分支變基
git rebase–interactive
交互式分支變基
git reflog
分支等引用變更記錄管理
git remote
遠程版本庫管理
git repo-config*
同義詞,等同於 git config
git reset
重置改變分支“游標”指向
git rev-parse
將各種引用表示法轉換為哈希值等
git revert
反轉提交
git rm
刪除文件
git show
顯示各種類型的對象
git stage*
同義詞,等同於 git add
git stash
保存和恢復進度
git status
顯示工作區文件狀態
git tag
里程碑管理
2、對象庫操作相關命令
命令
簡要說明
git commit-tree
從樹對象創建提交
git hash-object
從標准輸入或文件計算哈希值或創建對象
git ls-files
顯示工作區和暫存區文件
git ls-tree
顯示樹對象包含的文件
git mktag
讀取標准輸入創建一個里程碑對象
git mktree
讀取標准輸入創建一個樹對象
git read-tree
讀取樹對象到暫存區
git update-index
工作區內容注冊到暫存區及暫存區管理
git unpack-file
創建臨時文件包含指定 blob 的內容
git write-tree
從暫存區創建一個樹對象
3、引用操作相關命令
命令
簡要說明
git check-ref-format
檢查引用名稱是否符合規范
git for-each-ref
引用迭代器,用於shell編程
git ls-remote
顯示遠程版本庫的引用
git name-rev
將提交ID顯示為友好名稱
git peek-remote*
過時命令,請使用 git ls-remote
git rev-list
顯示版本范圍
git show-branch
顯示分支列表及拓撲關系
git show-ref
顯示本地引用
git symbolic-ref
顯示或者設置符號引用
git update-ref
更新引用的指向
git verify-tag
校驗 GPG 簽名的Tag
4、版本庫管理相關命令
命令
簡要說明
git count-objects
顯示松散對象的數量和磁盤占用
git filter-branch
版本庫重構
git fsck
對象庫完整性檢查
git fsck-objects*
同義詞,等同於 git fsck
git gc
版本庫存儲優化
git index-pack
從打包文件創建對應的索引文件
git lost-found*
過時,請使用 git fsck –lost-found 命令
git pack-objects
從標准輸入讀入對象ID,打包到文件
git pack-redundant
查找多余的 pack 文件
git pack-refs
將引用打包到 .git/packed-refs 文件中
git prune
從對象庫刪除過期對象
git prune-packed
將已經打包的松散對象刪除
git relink
為本地版本庫中相同的對象建立硬連接
git repack
將版本庫未打包的松散對象打包
git show-index
讀取包的索引文件,顯示打包文件中的內容
git unpack-objects
從打包文件釋放文件
git verify-pack
校驗對象庫打包文件
5、數據傳輸相關命令
命令
簡要說明
git fetch-pack
執行 git fetch 或 git pull 命令時在本地執行此命令,用於從其他版本庫獲取缺失的對象
git receive-pack
執行 git push 命令時在遠程執行的命令,用於接受推送的數據
git send-pack
執行 git push 命令時在本地執行的命令,用於向其他版本庫推送數據
git upload-archive
執行 git archive –remote 命令基於遠程版本庫創建歸檔時,遠程版本庫執行此命令傳送歸檔
git upload-pack
執行 git fetch 或 git pull 命令時在遠程執行此命令,將對象打包、上傳
6、郵件相關命令
命令
簡要說明
git imap-send
將補丁通過 IMAP 發送
git mailinfo
從郵件導出提交說明和補丁
git mailsplit
將 mbox 或 Maildir 格式郵箱中郵件逐一提取為文件
git request-pull
創建包含提交間差異和執行PULL操作地址的信息
git send-email
發送郵件
7、協議相關命令
命令
簡要說明
git daemon
實現Git協議
git http-backend
實現HTTP協議的CGI程序,支持智能HTTP協議
git instaweb
即時啟動瀏覽器通過 gitweb 瀏覽當前版本庫
git shell
受限制的shell,提供僅執行Git命令的SSH訪問
git update-server-info
更新啞協議需要的輔助文件
git http-fetch
通過HTTP協議獲取版本庫
git http-push
通過HTTP/DAV協議推送
git remote-ext
由Git命令調用,通過外部命令提供擴展協議支持
git remote-fd
由Git命令調用,使用文件描述符作為協議接口
git remote-ftp
由Git命令調用,提供對FTP協議的支持
git remote-ftps
由Git命令調用,提供對FTPS協議的支持
git remote-http
由Git命令調用,提供對HTTP協議的支持
git remote-https
由Git命令調用,提供對HTTPS協議的支持
git remote-testgit
協議擴展示例腳本
8、版本庫轉換和交互相關命令
命令
簡要說明
git archimport
導入Arch版本庫到Git
git bundle
提交打包和解包,以便在不同版本庫間傳遞
git cvsexportcommit
將Git的一個提交作為一個CVS檢出
git cvsimport
導入CVS版本庫到Git。或者使用 cvs2git
git cvsserver
Git的CVS協議模擬器,可供CVS命令訪問Git版本庫
git fast-export
將提交導出為 git-fast-import 格式
git fast-import
其他版本庫遷移至Git的通用工具
git svn
Git 作為前端操作 Subversion
9、合並相關的輔助命令
命令
簡要說明
git merge-base
供其他腳本調用,找到兩個或多個提交最近的共同祖先
git merge-file
針對文件的兩個不同版本執行三向文件合並
git merge-index
對index中的沖突文件調用指定的沖突解決工具
git merge-octopus
合並兩個以上分支。參見 git merge 的octopus合並策略
git merge-one-file
由 git merge-index 調用的標准輔助程序
git merge-ours
合並使用本地版本,拋棄他人版本。參見 git merge 的ours合並策略
git merge-recursive
針對兩個分支的三向合並。參見 git merge 的recursive合並策略
git merge-resolve
針對兩個分支的三向合並。參見 git merge 的resolve合並策略
git merge-subtree
子樹合並。參見 git merge 的 subtree 合並策略
git merge-tree
顯式三向合並結果,不改變暫存區
git fmt-merge-msg
供執行合並操作的腳本調用,用於創建一個合並提交說明
git rerere
重用所記錄的沖突解決方案
10、 雜項
命令
簡要說明
git bisect–helper
由 git bisect 命令調用,確認二分查找進度
git check-attr
顯示某個文件是否設置了某個屬性
git checkout-index
從暫存區拷貝文件至工作區
git cherry
查找沒有合並到上游的提交
git diff-files
比較暫存區和工作區,相當於 git diff –raw
git diff-index
比較暫存區和版本庫,相當於 git diff –cached –raw
git diff-tree
比較兩個樹對象,相當於 git diff –raw A B
git difftool–helper
由 git difftool 命令調用,默認要使用的差異比較工具
git get-tar-commit-id
從 git archive 創建的 tar 包中提取提交ID
git gui–askpass
命令 git gui 的獲取用戶口令輸入界面
git notes
提交評論管理
git patch-id
補丁過濾行號和空白字符后生成補丁唯一ID
git quiltimport
將Quilt補丁列表應用到當前分支
git replace
提交替換
git shortlog
對 git log 的匯總輸出,適合於產品發布說明
git stripspace
刪除空行,供其他腳本調用
git submodule
子模組管理
git tar-tree
過時命令,請使用 git archive
git var
顯示 Git 環境變量
git web–browse
啟動瀏覽器以查看目錄或文件
git whatchanged
顯示提交歷史及每次提交的改動
git-mergetool–lib
包含於其他腳本中,提供合並/差異比較工具的選擇和執行
git-parse-remote
包含於其他腳本中,提供操作遠程版本庫的函數
git-sh-setup
包含於其他腳本中,提供 shell 編程的函數庫
下面腳本之家小編特為大家分享一個圖片版的
Git 常用命令速查表。點擊查看大圖。
Git命令參考手冊(文本版)
git init # 初始化本地git倉庫(創建新倉庫)
git config --global user.name "xxx" # 配置用戶名
git config --global user.email "xxx@xxx.com" # 配置郵件
git config --global color.ui true # git status等命令自動着色
git config --global color.status auto
git config --global color.diff auto
git config --global color.branch auto
git config --global color.interactive auto
git clone git+ssh://git@192.168.53.168/VT.git # clone遠程倉庫
git status # 查看當前版本狀態(是否修改)
git add xyz # 添加xyz文件至index
git add . # 增加當前子目錄下所有更改過的文件至index
git commit -m 'xxx' # 提交
git commit --amend -m 'xxx' # 合並上一次提交(用於反復修改)
git commit -am 'xxx' # 將add和commit合為一步
git rm xxx # 刪除index中的文件
git rm -r * # 遞歸刪除
git log # 顯示提交日志
git log -1 # 顯示1行日志 -n為n行
git log -5
git log --stat # 顯示提交日志及相關變動文件
git log -p -m
git show dfb02e6e4f2f7b573337763e5c0013802e392818 # 顯示某個提交的詳細內容
git show dfb02 # 可只用commitid的前幾位
git show HEAD # 顯示HEAD提交日志
git show HEAD^ # 顯示HEAD的父(上一個版本)的提交日志 ^^為上兩個版本 ^5為上5個版本
git tag # 顯示已存在的tag
git tag -a v2.0 -m 'xxx' # 增加v2.0的tag
git show v2.0 # 顯示v2.0的日志及詳細內容
git log v2.0 # 顯示v2.0的日志
git diff # 顯示所有未添加至index的變更
git diff --cached # 顯示所有已添加index但還未commit的變更
git diff HEAD^ # 比較與上一個版本的差異
git diff HEAD -- ./lib # 比較與HEAD版本lib目錄的差異
git diff origin/master..master # 比較遠程分支master上有本地分支master上沒有的
git diff origin/master..master --stat # 只顯示差異的文件,不顯示具體內容
git remote add origin git+ssh://git@192.168.53.168/VT.git # 增加遠程定義(用於push/pull/fetch)
git branch # 顯示本地分支
git branch --contains 50089 # 顯示包含提交50089的分支
git branch -a # 顯示所有分支
git branch -r # 顯示所有原創分支
git branch --merged # 顯示所有已合並到當前分支的分支
git branch --no-merged # 顯示所有未合並到當前分支的分支
git branch -m master master_copy # 本地分支改名
git checkout -b master_copy # 從當前分支創建新分支master_copy並檢出
git checkout -b master master_copy # 上面的完整版
git checkout features/performance # 檢出已存在的features/performance分支
git checkout --track hotfixes/BJVEP933 # 檢出遠程分支hotfixes/BJVEP933並創建本地跟蹤分支
git checkout v2.0 # 檢出版本v2.0
git checkout -b devel origin/develop # 從遠程分支develop創建新本地分支devel並檢出
git checkout -- README # 檢出head版本的README文件(可用於修改錯誤回退)
git merge origin/master # 合並遠程master分支至當前分支
git cherry-pick ff44785404a8e # 合並提交ff44785404a8e的修改
git push origin master # 將當前分支push到遠程master分支
git push origin :hotfixes/BJVEP933 # 刪除遠程倉庫的hotfixes/BJVEP933分支
git push --tags # 把所有tag推送到遠程倉庫
git fetch # 獲取所有遠程分支(不更新本地分支,另需merge)
git fetch --prune # 獲取所有原創分支並清除服務器上已刪掉的分支
git pull origin master # 獲取遠程分支master並merge到當前分支
git mv README README2 # 重命名文件README為README2
git reset --hard HEAD # 將當前版本重置為HEAD(通常用於merge失敗回退)
git rebase
git branch -d hotfixes/BJVEP933 # 刪除分支hotfixes/BJVEP933(本分支修改已合並到其他分支)
git branch -D hotfixes/BJVEP933 # 強制刪除分支hotfixes/BJVEP933
git ls-files # 列出git index包含的文件
git show-branch # 圖示當前分支歷史
git show-branch --all # 圖示所有分支歷史
git whatchanged # 顯示提交歷史對應的文件修改
git revert dfb02e6e4f2f7b573337763e5c0013802e392818 # 撤銷提交dfb02e6e4f2f7b573337763e5c0013802e392818
git ls-tree HEAD # 內部命令:顯示某個git對象
git rev-parse v2.0 # 內部命令:顯示某個ref對於的SHA1 HASH
git reflog # 顯示所有提交,包括孤立節點
git show HEAD@{5}
git show master@{yesterday} # 顯示master分支昨天的狀態
git log --pretty=format:'%h %s' --graph # 圖示提交日志
git show HEAD~3
git show -s --pretty=raw 2be7fcb476
git stash # 暫存當前修改,將所有至為HEAD狀態
git stash list # 查看所有暫存
git stash show -p stash@{0} # 參考第一次暫存
git stash apply stash@{0} # 應用第一次暫存
git grep "delete from" # 文件中搜索文本“delete from”
git grep -e '#define' --and -e SORT_DIRENT
git gc
git fsck
Git 是一個很強大的分布式版本控制系統。它不但適用於管理大型開源軟件的源代碼,管理私人的文檔和源代碼也有很多優勢。
Git常用操作命令:
1) 遠程倉庫相關命令
檢出倉庫:$ git clone git://github.com/jquery/jquery.git
查看遠程倉庫:$ git remote -v
添加遠程倉庫:$ git remote add [name] [url]
刪除遠程倉庫:$ git remote rm [name]
修改遠程倉庫:$ git remote set-url --push [name] [newUrl]
拉取遠程倉庫:$ git pull [remoteName] [localBranchName]
推送遠程倉庫:$ git push [remoteName] [localBranchName]
*如果想把本地的某個分支test提交到遠程倉庫,並作為遠程倉庫的master分支,或者作為另外一個名叫test的分支,如下:
$git push origin test:master // 提交本地test分支作為遠程的master分支
$git push origin test:test // 提交本地test分支作為遠程的test分支
2)分支(branch)操作相關命令
查看本地分支:$ git branch
查看遠程分支:$ git branch -r
創建本地分支:$ git branch [name] ----注意新分支創建后不會自動切換為當前分支
切換分支:$ git checkout [name]
創建新分支並立即切換到新分支:$ git checkout -b [name]
刪除分支:$ git branch -d [name] ---- -d選項只能刪除已經參與了合並的分支,對於未有合並的分支是無法刪除的。如果想強制刪除一個分支,可以使用-D選項
合並分支:$ git merge [name] ----將名稱為[name]的分支與當前分支合並
創建遠程分支(本地分支push到遠程):$ git push origin [name]
刪除遠程分支:$ git push origin :heads/[name] 或 $ gitpush origin :[name]
*創建空的分支:(執行命令之前記得先提交你當前分支的修改,否則會被強制刪干凈沒得后悔)
$git symbolic-ref HEAD refs/heads/[name]
$rm .git/index
$git clean -fdx
3)版本(tag)操作相關命令
查看版本:$ git tag
創建版本:$ git tag [name]
刪除版本:$ git tag -d [name]
查看遠程版本:$ git tag -r
創建遠程版本(本地版本push到遠程):$ git push origin [name]
刪除遠程版本:$ git push origin :refs/tags/[name]
合並遠程倉庫的tag到本地:$ git pull origin --tags
上傳本地tag到遠程倉庫:$ git push origin --tags
創建帶注釋的tag:$ git tag -a [name] -m 'yourMessage'
4) 子模塊(submodule)相關操作命令
添加子模塊:$ git submodule add [url] [path]
如:$git submodule add git://github.com/soberh/ui-libs.git src/main/webapp/ui-libs
初始化子模塊:$ git submodule init ----只在首次檢出倉庫時運行一次就行
更新子模塊:$ git submodule update ----每次更新或切換分支后都需要運行一下
刪除子模塊:(分4步走哦)
1) $ git rm --cached [path]
2) 編輯“.gitmodules”文件,將子模塊的相關配置節點刪除掉
3) 編輯“ .git/config”文件,將子模塊的相關配置節點刪除掉
4) 手動刪除子模塊殘留的目錄
5)忽略一些文件、文件夾不提交
在倉庫根目錄下創建名稱為“.gitignore”的文件,寫入不需要的文件夾名或文件,每個元素占一行即可,如
target
bin
*.db
=====================
Git 常用命令
git branch 查看本地所有分支
git status 查看當前狀態
git commit 提交
git branch -a 查看所有的分支
git branch -r 查看本地所有分支
git commit -am "init" 提交並且加注釋
git remote add origin git@192.168.1.119:ndshow
git push origin master 將文件給推到服務器上
git remote show origin 顯示遠程庫origin里的資源
git push origin master:develop
git push origin master:hb-dev 將本地庫與服務器上的庫進行關聯
git checkout --track origin/dev 切換到遠程dev分支
git branch -D master develop 刪除本地庫develop
git checkout -b dev 建立一個新的本地分支dev
git merge origin/dev 將分支dev與當前分支進行合並
git checkout dev 切換到本地dev分支
git remote show 查看遠程庫
git add .
git rm 文件名(包括路徑) 從git中刪除指定文件
git clone git://github.com/schacon/grit.git 從服務器上將代碼給拉下來
git config --list 看所有用戶
git ls-files 看已經被提交的
git rm [file name] 刪除一個文件
git commit -a 提交當前repos的所有的改變
git add [file name] 添加一個文件到git index
git commit -v 當你用-v參數的時候可以看commit的差異
git commit -m "This is the message describing the commit" 添加commit信息
git commit -a -a是代表add,把所有的change加到git index里然后再commit
git commit -a -v 一般提交命令
git log 看你commit的日志
git diff 查看尚未暫存的更新
git rm a.a 移除文件(從暫存區和工作區中刪除)
git rm --cached a.a 移除文件(只從暫存區中刪除)
git commit -m "remove" 移除文件(從Git中刪除)
git rm -f a.a 強行移除修改后文件(從暫存區和工作區中刪除)
git diff --cached 或 $ git diff --staged 查看尚未提交的更新
git stash push 將文件給push到一個臨時空間中
git stash pop 將文件從臨時空間pop下來
---------------------------------------------------------
git remote add origin git@github.com:username/Hello-World.git
git push origin master 將本地項目給提交到服務器中
-----------------------------------------------------------
git pull 本地與服務器端同步
-----------------------------------------------------------------
git push (遠程倉庫名) (分支名) 將本地分支推送到服務器上去。
git push origin serverfix:awesomebranch
------------------------------------------------------------------
git fetch 相當於是從遠程獲取最新版本到本地,不會自動merge
git commit -a -m "log_message" (-a是提交所有改動,-m是加入log信息) 本地修改同步至服務器端 :
git branch branch_0.1 master 從主分支master創建branch_0.1分支
git branch -m branch_0.1 branch_1.0 將branch_0.1重命名為branch_1.0
git checkout branch_1.0/master 切換到branch_1.0/master分支
du -hs
-----------------------------------------------------------
mkdir WebApp
cd WebApp
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin git@github.com:daixu/WebApp.git
git push -u origin master