自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

常用的Git命令清單

系統(tǒng) Linux
一般來(lái)說(shuō),日常使用只要記住下圖6個(gè)命令,就可以了。但是熟練使用,恐怕要記住60~100個(gè)命令。

常用Git命令清單

一般來(lái)說(shuō),日常使用只要記住下圖6個(gè)命令,就可以了。但是熟練使用,恐怕要記住60~100個(gè)命令。

名次解釋

下面是我整理的常用 Git 命令清單。幾個(gè)專(zhuān)用名詞的譯名如下: Workspace:工作區(qū) Index / Stage:暫存區(qū) Repository:倉(cāng)庫(kù)區(qū)(或本地倉(cāng)庫(kù)) Remote:遠(yuǎn)程倉(cāng)庫(kù)

一. 新建代碼庫(kù) 

  1. # 在當(dāng)前目錄新建一個(gè)Git代碼庫(kù)  
  2. $ git init  
  3. # 新建一個(gè)目錄,將其初始化為Git代碼庫(kù)  
  4. $ git init [project-name]  
  5. # 下載一個(gè)項(xiàng)目和它的整個(gè)代碼歷史  
  6. $ git clone [url] 

二.配置

Git的設(shè)置文件為.gitconfig,它可以在用戶(hù)主目錄下(全局配置),也可以在項(xiàng)目目錄下(項(xiàng)目配置) 

  1. # 顯示當(dāng)前的Git配置  
  2. $ git config --list   
  3. # 編輯Git配置文件  
  4. $ git config -e [--global]  
  5. # 設(shè)置提交代碼時(shí)的用戶(hù)信息  
  6. $ git config [--global] user.name "[name]"  
  7. $ git config [--global] user.email "[email address]"  
  8. # 顏色設(shè)置  
  9. git config --global color.ui true                         # git status等命令自動(dòng)著色  
  10. git config --global color.status auto  
  11. git config --global color.diff auto  
  12. git config --global color.branch auto  
  13. git config --global color.interactive auto  
  14. git config --global --unset http.proxy                    # remove  proxy configuration on git 

三. 增加/刪除文件 

  1. # 添加指定文件到暫存區(qū)  
  2. $ git add [file1] [file2] ...  
  3. # 添加指定目錄到暫存區(qū),包括子目錄  
  4. $ git add [dir]  
  5. # 添加當(dāng)前目錄的所有文件到暫存區(qū)  
  6. $ git add .  
  7. # 添加每個(gè)變化前,都會(huì)要求確認(rèn)  
  8. # 對(duì)于同一個(gè)文件的多處變化,可以實(shí)現(xiàn)分次提交 
  9. $ git add -p  
  10. # 刪除工作區(qū)文件,并且將這次刪除放入暫存區(qū)  
  11. $ git rm [file1] [file2] ...  
  12. # 停止追蹤指定文件,但該文件會(huì)保留在工作區(qū)  
  13. $ git rm --cached [file]  
  14. # 改名文件,并且將這個(gè)改名放入暫存區(qū)  
  15. $ git mv [file-original] [file-renamed] 

四. 代碼提交 

  1. # 提交暫存區(qū)到倉(cāng)庫(kù)區(qū)  
  2. $ git commit -m [message]  
  3. # 提交暫存區(qū)的指定文件到倉(cāng)庫(kù)區(qū)  
  4. $ git commit [file1] [file2] ... -m [message]  
  5. # 提交工作區(qū)自上次commit之后的變化,直接到倉(cāng)庫(kù)區(qū)  
  6. $ git commit -a  
  7. # 提交時(shí)顯示所有diff信息  
  8. $ git commit -v  
  9. # 將add和commit合為一步  
  10. $ git commit -am 'message'  
  11. # 使用一次新的commit,替代上一次提交  
  12. # 如果代碼沒(méi)有任何新變化,則用來(lái)改寫(xiě)上一次commit的提交信息  
  13. $ git commit --amend -m [message]  
  14. # 重做上一次commit,并包括指定文件的新變化  
  15. $ git commit --amend [file1] [file2] ... 

五. 分支 

  1. # 列出所有本地分支  
  2. $ git branch  
  3. # 列出所有遠(yuǎn)程分支  
  4. $ git branch -r  
  5. # 列出所有本地分支和遠(yuǎn)程分支  
  6. $ git branch -a  
  7. # 新建一個(gè)分支,但依然停留在當(dāng)前分支  
  8. $ git branch [branch-name]  
  9. # 新建一個(gè)分支,并切換到該分支  
  10. $ git checkout -b [branch]  
  11. # 新建一個(gè)分支,指向指定commit  
  12. $ git branch [branch] [commit]  
  13. # 新建一個(gè)分支,與指定的遠(yuǎn)程分支建立追蹤關(guān)系  
  14. $ git branch --track [branch] [remote-branch]  
  15. # 切換到指定分支,并更新工作區(qū)  
  16. $ git checkout [branch-name]  
  17. # 切換到上一個(gè)分支  
  18. $ git checkout - 
  19. # 建立追蹤關(guān)系,在現(xiàn)有分支與指定的遠(yuǎn)程分支之間  
  20. $ git branch --set-upstream [branch] [remote-branch]  
  21. # 合并指定分支到當(dāng)前分支  
  22. $ git merge [branch]  
  23. # 選擇一個(gè)commit,合并進(jìn)當(dāng)前分支  
  24. $ git cherry-pick [commit]  
  25. # 刪除分支  
  26. $ git branch -d [branch-name]  
  27. # 刪除遠(yuǎn)程分支  
  28. $ git push origin --delete [branch-name]  
  29. $ git branch -dr [remote/branch]  
  30. # 檢出版本v2.0  
  31. $ git checkout v2.0  
  32. # 從遠(yuǎn)程分支develop創(chuàng)建新本地分支devel并檢出  
  33. $ git checkout -b devel origin/develop  
  34. # 檢出head版本的README文件(可用于修改錯(cuò)誤回退)  
  35. git checkout -- README                                 

 六. 標(biāo)簽 

  1. # 列出所有tag  
  2. $ git tag  
  3. # 新建一個(gè)tag在當(dāng)前commit  
  4. $ git tag [tag]  
  5. # 新建一個(gè)tag在指定commit  
  6. $ git tag [tag] [commit]  
  7. # 刪除本地tag  
  8. $ git tag -d [tag] 
  9. # 刪除遠(yuǎn)程tag  
  10. $ git push origin :refs/tags/[tagName]  
  11. # 查看tag信息  
  12. $ git show [tag]  
  13. # 提交指定tag  
  14. $ git push [remote] [tag]  
  15. # 提交所有tag  
  16. $ git push [remote] --tags  
  17. # 新建一個(gè)分支,指向某個(gè)tag  
  18. $ git checkout -b [branch] [tag] 

七. 查看信息 

  1. # 顯示有變更的文件  
  2. $ git status  
  3. # 顯示當(dāng)前分支的版本歷史  
  4. $ git log  
  5. # 顯示commit歷史,以及每次commit發(fā)生變更的文件  
  6. $ git log --stat  
  7. # 搜索提交歷史,根據(jù)關(guān)鍵詞  
  8. $ git log -S [keyword]  
  9. # 顯示某個(gè)commit之后的所有變動(dòng),每個(gè)commit占據(jù)一行  
  10. $ git log [tag] HEAD --pretty=format:%s  
  11. # 顯示某個(gè)commit之后的所有變動(dòng),其"提交說(shuō)明"必須符合搜索條件  
  12. $ git log [tag] HEAD --grep feature  
  13. # 顯示某個(gè)文件的版本歷史,包括文件改名  
  14. $ git log --follow [file]  
  15. $ git whatchanged [file]  
  16. # 顯示指定文件相關(guān)的每一次diff  
  17. $ git log -p [file]  
  18. # 顯示過(guò)去5次提交  
  19. $ git log -5 --pretty --oneline  
  20. # 顯示所有提交過(guò)的用戶(hù),按提交次數(shù)排序  
  21. $ git shortlog -sn  
  22. # 顯示指定文件是什么人在什么時(shí)間修改過(guò)  
  23. $ git blame [file]  
  24. # 顯示暫存區(qū)和工作區(qū)的差異  
  25. $ git diff  
  26. # 顯示暫存區(qū)和上一個(gè)commit的差異  
  27. $ git diff --cached [file]  
  28. # 顯示工作區(qū)與當(dāng)前分支最新commit之間的差異  
  29. $ git diff HEAD  
  30. # 顯示兩次提交之間的差異  
  31. $ git diff [first-branch]...[second-branch]  
  32. # 顯示今天你寫(xiě)了多少行代碼  
  33. $ git diff --shortstat "@{0 day ago}"  
  34. # 顯示某次提交的元數(shù)據(jù)和內(nèi)容變化  
  35. $ git show [commit]  
  36. # 顯示某次提交發(fā)生變化的文件  
  37. $ git show --name-only [commit]  
  38. # 顯示某次提交時(shí),某個(gè)文件的內(nèi)容  
  39. $ git show [commit]:[filename]  
  40. # 顯示當(dāng)前分支的最近幾次提交  
  41. $ git reflog 

八. 遠(yuǎn)程同步 

  1. # 下載遠(yuǎn)程倉(cāng)庫(kù)的所有變動(dòng)  
  2. $ git fetch [remote]  
  3. # 顯示所有遠(yuǎn)程倉(cāng)庫(kù)  
  4. $ git remote -v  
  5. # 顯示某個(gè)遠(yuǎn)程倉(cāng)庫(kù)的信息  
  6. $ git remote show [remote]  
  7. # 增加一個(gè)新的遠(yuǎn)程倉(cāng)庫(kù),并命名  
  8. $ git remote add [shortname] [url]  
  9. # 取回遠(yuǎn)程倉(cāng)庫(kù)的變化,并與本地分支合并  
  10. $ git pull [remote] [branch]  
  11. # 上傳本地指定分支到遠(yuǎn)程倉(cāng)庫(kù)  
  12. $ git push [remote] [branch]  
  13. # 強(qiáng)行推送當(dāng)前分支到遠(yuǎn)程倉(cāng)庫(kù),即使有沖突  
  14. $ git push [remote] --force  
  15. # 推送所有分支到遠(yuǎn)程倉(cāng)庫(kù)  
  16. $ git push [remote] --all 

九. 撤銷(xiāo) 

  1. # 恢復(fù)暫存區(qū)的指定文件到工作區(qū)  
  2. $ git checkout [file]  
  3. # 恢復(fù)某個(gè)commit的指定文件到暫存區(qū)和工作區(qū) 
  4. $ git checkout [commit] [file]  
  5. # 恢復(fù)暫存區(qū)的所有文件到工作區(qū)  
  6. $ git checkout .  
  7. # 重置暫存區(qū)的指定文件,與上一次commit保持一致,但工作區(qū)不變  
  8. $ git reset [file]  
  9. # 重置暫存區(qū)與工作區(qū),與上一次commit保持一致  
  10. $ git reset --hard  
  11. # 重置當(dāng)前分支的指針為指定commit,同時(shí)重置暫存區(qū),但工作區(qū)不變 
  12. $ git reset [commit]  
  13. # 重置當(dāng)前分支的HEAD為指定commit,同時(shí)重置暫存區(qū)和工作區(qū),與指定commit一致  
  14. $ git reset --hard [commit]  
  15. # 重置當(dāng)前HEAD為指定commit,但保持暫存區(qū)和工作區(qū)不變  
  16. $ git reset --keep [commit]  
  17. # 新建一個(gè)commit,用來(lái)撤銷(xiāo)指定commit  
  18. # 后者的所有變化都將被前者抵消,并且應(yīng)用到當(dāng)前分支 
  19. $ git revert [commit]  
  20. # 暫時(shí)將未提交的變化移除,稍后再移入  
  21. $ git stash 
  22. $ git stash pop 

十. 其他 

  1. git init                                                  # 初始化本地git倉(cāng)庫(kù)(創(chuàng)建新倉(cāng)庫(kù))  
  2. git config --global user.name "xxx"                       # 配置用戶(hù)名  
  3. git config --global user.email "xxx@xxx.com"              # 配置郵件  
  4. git config --global color.ui true                         # git status等命令自動(dòng)著色  
  5. git config --global color.status auto  
  6. git config --global color.diff auto 
  7. git config --global color.branch auto  
  8. git config --global color.interactive auto  
  9. git config --global --unset http.proxy                    # remove  proxy configuration on git  
  10. git clone git+ssh://git@192.168.53.168/VT.git             # clone遠(yuǎn)程倉(cāng)庫(kù) 
  11.  git status                                                # 查看當(dāng)前版本狀態(tài)(是否修改)  
  12. git add xyz                                               # 添加xyz文件至index 
  13.  git add .                                                 # 增加當(dāng)前子目錄下所有更改過(guò)的文件至index  
  14. git commit -m 'xxx'                                       # 提交  
  15. git commit --amend -m 'xxx'                               # 合并上一次提交(用于反復(fù)修改)  
  16. git commit -am 'xxx'                                      # 將add和commit合為一步  
  17. git rm xxx                                                # 刪除index中的文件  
  18. git rm -r *                                               # 遞歸刪除  
  19. git log                                                   # 顯示提交日志  
  20. git log -1                                                # 顯示1行日志 -n為n行  
  21. git log -5  
  22. git log --stat                                            # 顯示提交日志及相關(guān)變動(dòng)文件  
  23. git log -p -m  
  24. git show dfb02e6e4f2f7b573337763e5c0013802e392818         # 顯示某個(gè)提交的詳細(xì)內(nèi)容  
  25. git show dfb02                                            # 可只用commitid的前幾位  
  26. git show HEAD                                             # 顯示HEAD提交日志 
  27. git show HEAD^                                            # 顯示HEAD的父(上一個(gè)版本)的提交日志 ^^為上兩個(gè)版本 ^5為上5個(gè)版本  
  28. git tag                                                   # 顯示已存在的tag  
  29. git tag -a v2.0 -m 'xxx'                                  # 增加v2.0的tag  
  30. git show v2.0                                             # 顯示v2.0的日志及詳細(xì)內(nèi)容  
  31. git log v2.0                                              # 顯示v2.0的日志  
  32. git diff                                                  # 顯示所有未添加至index的變更  
  33. git diff --cached                                         # 顯示所有已添加index但還未commit的變更  
  34. git diff HEAD^                                            # 比較與上一個(gè)版本的差異  
  35. git diff HEAD -- ./lib                                    # 比較與HEAD版本lib目錄的差異  
  36. git diff origin/master..master                            # 比較遠(yuǎn)程分支master上有本地分支master上沒(méi)有的  
  37. git diff origin/master..master --stat                     # 只顯示差異的文件,不顯示具體內(nèi)容  
  38. git remote add origin git+ssh://git@192.168.53.168/VT.git # 增加遠(yuǎn)程定義(用于push/pull/fetch)  
  39. git branch                                                # 顯示本地分支  
  40. git branch --contains 50089                               # 顯示包含提交50089的分支  
  41. git branch -a                                             # 顯示所有分支  
  42. git branch -r                                             # 顯示所有原創(chuàng)分支  
  43. git branch --merged                                       # 顯示所有已合并到當(dāng)前分支的分支  
  44. git branch --no-merged                                    # 顯示所有未合并到當(dāng)前分支的分支  
  45. git branch -m master master_copy                          # 本地分支改名  
  46. git checkout -b master_copy                               # 從當(dāng)前分支創(chuàng)建新分支master_copy并檢出  
  47. git checkout -b master master_copy                        # 上面的完整版  
  48. git checkout features/performance                         # 檢出已存在的features/performance分支  
  49. git checkout --track hotfixes/BJVEP933                    # 檢出遠(yuǎn)程分支hotfixes/BJVEP933并創(chuàng)建本地跟蹤分支  
  50. git checkout v2.0                                         # 檢出版本v2.0  
  51. git checkout -b devel origin/develop                      # 從遠(yuǎn)程分支develop創(chuàng)建新本地分支devel并檢出  
  52. git checkout -- README                                    # 檢出head版本的README文件(可用于修改錯(cuò)誤回退)  
  53. git merge origin/master                                   # 合并遠(yuǎn)程master分支至當(dāng)前分支  
  54. git cherry-pick ff44785404a8e                             # 合并提交ff44785404a8e的修改  
  55. git push origin master                                    # 將當(dāng)前分支push到遠(yuǎn)程master分支  
  56. git push origin :hotfixes/BJVEP933                        # 刪除遠(yuǎn)程倉(cāng)庫(kù)的hotfixes/BJVEP933分支  
  57. git push --tags                                           # 把所有tag推送到遠(yuǎn)程倉(cāng)庫(kù)  
  58. git fetch                                                 # 獲取所有遠(yuǎn)程分支(不更新本地分支,另需merge)  
  59. git fetch --prune                                         # 獲取所有原創(chuàng)分支并清除服務(wù)器上已刪掉的分支  
  60. git pull origin master                                    # 獲取遠(yuǎn)程分支master并merge到當(dāng)前分支  
  61. git mv README README2                                     # 重命名文件README為README2  
  62. git reset --hard HEAD                                     # 將當(dāng)前版本重置為HEAD(通常用于merge失敗回退) 
  63. git rebase  
  64. git branch -d hotfixes/BJVEP933                           # 刪除分支hotfixes/BJVEP933(本分支修改已合并到其他分支)  
  65. git branch -D hotfixes/BJVEP933                           # 強(qiáng)制刪除分支hotfixes/BJVEP933  
  66. git ls-files                                              # 列出git index包含的文件 
  67. git show-branch                                           # 圖示當(dāng)前分支歷史  
  68. git show-branch --all                                     # 圖示所有分支歷史  
  69. git whatchanged                                           # 顯示提交歷史對(duì)應(yīng)的文件修改  
  70. git revert dfb02e6e4f2f7b573337763e5c0013802e392818       # 撤銷(xiāo)提交dfb02e6e4f2f7b573337763e5c0013802e392818  
  71. git ls-tree HEAD                                          # 內(nèi)部命令:顯示某個(gè)git對(duì)象  
  72. git rev-parse v2.0                                        # 內(nèi)部命令:顯示某個(gè)ref對(duì)于的SHA1 HASH  
  73. git reflog                                                # 顯示所有提交,包括孤立節(jié)點(diǎn)  
  74. git show HEAD@{5}  
  75. git show master@{yesterday}                               # 顯示master分支昨天的狀態(tài)  
  76. git log --pretty=format:'%h %s' --graph                   # 圖示提交日志  
  77. git show HEAD~3  
  78. git show -s --pretty=raw 2be7fcb476  
  79. git stash                                                 # 暫存當(dāng)前修改,將所有至為HEAD狀態(tài)  
  80. git stash list                                            # 查看所有暫存  
  81. git stash show -p stash@{0}                               # 參考第一次暫存  
  82. git stash apply stash@{0}                                 # 應(yīng)用第一次暫存  
  83. git grep "delete from"                                    # 文件中搜索文本“delete from”  
  84. git grep -e '#define' --and -e SORT_DIRENT  
  85. git gc  
  86. git fsck  
  87. # 生成一個(gè)可供發(fā)布的壓縮包  
  88. $ git archive 

 【編輯推薦】

 

責(zé)任編輯:龐桂玉 來(lái)源: 馬哥Linux運(yùn)維
相關(guān)推薦

2015-12-10 09:43:23

Git命令清單

2015-07-28 10:21:23

git命令

2021-08-11 08:53:23

Git命令面試

2024-10-16 15:25:15

2018-05-29 15:53:01

LinuxGit常用命令

2020-06-08 09:15:14

前端 開(kāi)發(fā) Git

2024-03-01 13:48:00

Git配置系統(tǒng)

2020-10-27 07:31:35

GitGit RevertGit Reset

2010-07-14 15:52:28

Telnet命令

2022-07-21 11:01:21

Docker容器

2016-08-03 16:27:47

GitLinux開(kāi)源

2020-08-17 09:31:31

Git命令開(kāi)發(fā)

2011-02-21 12:54:47

postfix命令

2022-12-07 13:58:26

Git命令

2019-06-19 09:00:00

GitLinux開(kāi)源

2010-05-19 18:23:34

2010-06-28 15:06:24

ftp子命令

2010-10-08 11:00:40

常用mysql命令

2023-08-31 22:45:15

Git命令效率

2021-05-27 05:34:22

Git開(kāi)源控制系統(tǒng)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)