2016.09.10
最近項目版本管理從SVN切換到Git喘垂,下面記錄下實際當中常用到的一些命令,方便查閱侄泽。
當然礁芦,GUI操作的工具非常不錯,但是命令行操作那 “
鍵指如飛
” 的感覺相當吸引我悼尾。
vim的一些常用命令:
按下ESC
鍵柿扣,退出編輯模式,切換到命令模式:
Vim命令 | 命令說明 |
---|---|
vi filename
|
創(chuàng)建打開文件 |
:w | 保存 |
:q | 退出 |
ZZ闺魏、:wq | 保存退出 |
ZQ未状、:q! | 退出不保存 |
:e! | 放棄修改 |
:w filename
|
另存為 |
x | 刪除當前光標下的字符 |
X | 刪除當前光標左邊的字符 |
s | 修改一個字符 |
i | 在光標之前插入 |
a | 在光標之后插入 |
diw | 刪除光標所在的單詞,不包括空白字符 |
daw | 刪除光標所在的單詞析桥,包括空白字符 |
dw | 從當前位置刪除到下一個單詞詞音 |
D | 刪除到行尾的內(nèi)容 |
C | 修改到行尾的內(nèi)容 |
S | 修改一整行 |
dd | 刪除一整行 |
yy | 復(fù)制一整行 |
u | 撤銷改動 |
P | 粘貼到光標之前 |
p | 粘貼到光標之后 |
d | 剪切 |
:set nu! | 顯示行號 |
:set autoindent | 自動縮進 |
:set warp | 自動換行 |
下面這張示意圖是從VIM常用命令示意圖找來的:
git的一些常用命令操作:
記錄跟蹤:
Git命令 | 命令說明 |
---|---|
git status | 檢查當前文件狀態(tài) |
git status -s | 狀態(tài)簡覽 |
git add filename
|
跟蹤新文件 (已暫存狀態(tài)) |
cat .gitignore | 列出要忽略的文件模式 |
git diff | 查看已暫存和未暫存的修改 |
git diff --cached (git diff --staged ) |
若要查看已暫存的將要添加到下次提交里的內(nèi)容 |
提交更新司草、移動、移除:
Git命令 | 命令說明 |
---|---|
git commit | 提交更新 |
git commit -m "commit info " |
提交更新,并添加提交信息 |
git commit -a -m "commit info " |
跳過使用暫存區(qū)域 |
rm filename
|
移除文件 |
git rm filename
|
記錄此次移除文件的操作 |
git rm --cached filename
|
讓文件保留在磁盤泡仗,但不想讓Git繼續(xù)跟蹤 |
git rm log/ *.log
|
刪除log/目錄下擴展名為.log的所有文件 |
git mv file_from file_to
|
移動文件 |
提交歷史:
Git命令 | 命令說明 |
---|---|
git log | 查看提交歷史 |
git log -p -2
|
顯示最近兩次提交的內(nèi)容差異 |
git log --pretty=oneline 埋虹、git log --pretty=format:"%h - %an,%ar : %s" 、git log --pretty=format:"%h %s" --graph
|
指定使用不同于默認格式的方式展示提交歷史(oneline娩怎、short搔课、full、fuller) |
git log --since=2.weeks
|
日志限制輸出長度 |
git log -Sfunction_name
|
某一個特定函數(shù)的引用的提交 |
git log --since="2016-09-07 " |
指定時間之后提交信息 |
git commit --amend | 重新提交 |
git reset HEAD filename
|
取消暫存的文件 |
git checkout -- filename
|
撤銷對文件的修改 |
遠程倉庫:
Git命令 | 命令說明 |
---|---|
git clone https://example.com/gitproject.git
|
克隆現(xiàn)有的倉庫 |
git clone https://example.com/gitproject.git myTest
|
并設(shè)置本地倉庫名字 |
git remote | 查看遠程倉庫 |
git remote -v | 讀寫遠程倉庫使用的Git保存的簡寫與其對應(yīng)的URL |
git remote add test https://example.com/gitproject.git
|
添加遠程倉庫 |
git fetch remote-name
|
從遠程倉庫中抓取與拉取 |
git push remote-name branch-name
|
推送到遠程倉庫 |
git remote show origin
|
查看遠程倉庫 |
git remote rename testProject test
|
遠程倉庫重命名 |
git remote rm test
|
遠程倉庫移除 |
標簽:
Git命令 | 命令說明 |
---|---|
git tag | 列出標簽 |
git tag -l 'v1.6.2 ' |
以特定的模式查找標簽 |
git tag -a v1.6.3 -m 'my version 1.6.3 ' |
創(chuàng)建并附注標簽 |
git show v1.6.3
|
查看標簽信息以及對應(yīng)的提交信息 |
git tag v1.4-lw
|
輕量標簽 |
git tag -a v1.2 9fceb02
|
后期打標簽(校驗和) |
git push origin v1.5
|
共享標簽 |
git push origin --tags | 共享標簽tags |
git checkout -b branchname tagname
|
檢出標簽 |
別名:
Git命令 | 命令說明 |
---|---|
git config --global alias.last 'log -1 HEAD' --> git last
|
查看最后一次提交 |
分支:
Git命令 | 命令說明 |
---|---|
git branch test
|
分支創(chuàng)建 |
git log --oneline --decorate | 查看各個分支當前所指的對象 |
git log --oneline --decorate --graph --all | 查看分支歷史 |
git checkout test
|
分支切換 |
git checkout -b test01
|
新建分支并同時切換到那個分支上 |
git merge test01
|
合并分支 |
git branch -d test01
|
刪除分支 |
git branch | 查看所有分支 |
git branch -v | 查看每一個分支的最后一次提交 |
git branch --merged | 查看哪些分支已經(jīng)合并到當前分支 |
git branch --no-merged | 查看所有包含未合并工作的分支 |
git push --set-upstream origin test01
|
把本地分支推送到遠程 |
遠程分支:
Git命令 | 命令說明 |
---|---|
git ls-remote origin | 獲取遠程引用的完整列表 |
git remote show origin | 獲取遠程分支更多的信息 |
git push origin testFix:testFix
|
推送本地分支作為遠程分支 |
git checkout --track origin/testFix
|
跟蹤分支 |
git checkout -b sf origin/testFix
|
將本地分支與遠程分支設(shè)置為不用名字 |
git branch -vv | 將本地分支列出并包含更多的信息 |
git push origin --delete test
|
刪除遠程分支 |
協(xié)議:
Git命令 | 命令說明 |
---|---|
git remote add local_proj /opt/git/project.git
|
添加一個本地版本到現(xiàn)有的Git項目 |
git clone ssh://user@server/project.git
|
SSH協(xié)議 |
git clone https://example.com/gitproject.git
|
HHTP協(xié)議 |