偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

學(xué)會 Git 命令就是這么簡單

系統(tǒng) Linux
下面是我收錄整理的常用和不常用的一些 Git 命令,希望能幫助到大家更好的掌握 Git 的使用。

 

我平時使用 Git 的時候,很多的 Git 命令我都不是很常用,工作中一般我們會配合一些可視化工具,或者編輯器自帶的一些插件去維護 Git 倉庫,但是我們也要記得一些常用 Git 命令來應(yīng)變一些特殊的場景,下面是我收錄整理的常用和不常用的一些 Git 命令,希望能幫助到大家更好的掌握 Git 的使用,如果文章和筆記能帶您一絲幫助或者啟發(fā),請不要吝嗇你的贊和收藏,你的肯定是我前進的最大動力😁

新建

創(chuàng)建一個新的 git 版本庫。這個版本庫的配置、存儲等信息會被保存到.git 文件夾中 

  1. # 初始化當(dāng)前項目  
  2. $ git init  
  3. # 新建一個目錄,將其初始化為Git代碼庫  
  4. $ git init [project-name]  
  5. # 在指定目錄創(chuàng)建一個空的 Git 倉庫。運行這個命令會創(chuàng)建一個名為 directory,只包含 .git 子目錄的空目錄。  
  6. $ git init --bare <directory>  
  7. # 下載一個項目和它的整個代碼歷史  
  8. # 這個命令就是將一個版本庫拷貝到另一個目錄中,同時也將分支都拷貝到新的版本庫中。這樣就可以在新的版本庫中提交到遠程分支  
  9. $ git clone [url] 

配置

更改設(shè)置??梢允前姹編斓脑O(shè)置,也可以是系統(tǒng)的或全局的 

  1. # 顯示當(dāng)前的Git配置  
  2. $ git config --list  
  3. # 編輯Git配置文件  
  4. $ git config -e [--global] 
  5. # 輸出、設(shè)置基本的全局變量  
  6. $ git config --global user.email  
  7. $ git config --global user.name  
  8. $ git config --global user.email "MyEmail@gmail.com"  
  9. $ git config --global user.name "My Name"  
  10. # 定義當(dāng)前用戶所有提交使用的作者郵箱。  
  11. $ git config --global alias.<alias-name> <git-command>  
  12. # 為Git命令創(chuàng)建一個快捷方式(別名)。  
  13. $ git config --system core.editor <editor> 

幫助

git 內(nèi)置了對命令非常詳細(xì)的解釋,可以供我們快速查閱 

  1. # 查找可用命令  
  2. $ git help  
  3. # 查找所有可用命令  
  4. $ git help -a  
  5. # 在文檔當(dāng)中查找特定的命令  
  6. # git help <命令>  
  7. $ git help add  
  8. $ git help commit  
  9. $ git help init 

狀態(tài)

顯示索引文件(也就是當(dāng)前工作空間)和當(dāng)前的頭指針指向的提交的不同 

  1. # 顯示分支,未跟蹤文件,更改和其他不同  
  2. $ git status  
  3. # 查看其他的git status的用法  
  4. $ git help status 

信息

獲取某些文件,某些分支,某次提交等 git 信息 

  1. # 顯示commit歷史,以及每次commit發(fā)生變更的文件  
  2. $ git log --stat  
  3. # 搜索提交歷史,根據(jù)關(guān)鍵詞  
  4. $ git log -S [keyword]  
  5. # 顯示某個commit之后的所有變動,每個commit占據(jù)一行  
  6. $ git log [tag] HEAD --pretty=format:%s  
  7. # 顯示某個commit之后的所有變動,其"提交說明"必須符合搜索條件  
  8. $ git log [tag] HEAD --grep feature  
  9. # 顯示某個文件的版本歷史,包括文件改名  
  10. $ git log --follow [file]  
  11. $ git whatchanged [file]  
  12. # 顯示指定文件相關(guān)的每一次diff  
  13. $ git log -p [file]  
  14. # 顯示過去5次提交  
  15. $ git log -5 --pretty --oneline  
  16. # 顯示所有提交過的用戶,按提交次數(shù)排序  
  17. $ git shortlog -sn  
  18. # 顯示指定文件是什么人在什么時間修改過  
  19. $ git blame [file]  
  20. # 顯示暫存區(qū)和工作區(qū)的差異  
  21. $ git diff  
  22. # 顯示暫存區(qū)和上一個commit的差異  
  23. $ git diff --cached [file]  
  24. # 顯示工作區(qū)與當(dāng)前分支最新commit之間的差異  
  25. $ git diff HEAD  
  26. # 顯示兩次提交之間的差異  
  27. $ git diff [first-branch]...[second-branch]  
  28. # 顯示今天你寫了多少行代碼  
  29. $ git diff --shortstat "@{0 day ago}"  
  30. # 比較暫存區(qū)和版本庫差異  
  31. $ git diff --staged  
  32. # 比較暫存區(qū)和版本庫差異  
  33. $ git diff --cached  
  34. # 僅僅比較統(tǒng)計信息  
  35. $ git diff --stat  
  36. # 顯示某次提交的元數(shù)據(jù)和內(nèi)容變化  
  37. $ git show [commit]  
  38. # 顯示某次提交發(fā)生變化的文件  
  39. $ git show --name-only [commit]  
  40. # 顯示某次提交時,某個文件的內(nèi)容  
  41. $ git show [commit]:[filename]  
  42. # 顯示當(dāng)前分支的最近幾次提交  
  43. $ git reflog  
  44. # 查看遠程分支  
  45. $ git br -r  
  46. # 創(chuàng)建新的分支  
  47. $ git br <new_branch>  
  48. # 查看各個分支最后提交信息  
  49. $ git br -v  
  50. # 查看已經(jīng)被合并到當(dāng)前分支的分支  
  51. $ git br --merged  
  52. # 查看尚未被合并到當(dāng)前分支的分支  
  53. $ git br --no-merged 

添加

添加文件到當(dāng)前工作空間中。如果你不使用 git add 將文件添加進去,那么這些文件也不會添加到之后的提交之中 

  1. # 添加一個文件  
  2. $ git add test.js  
  3. # 添加一個子目錄中的文件  
  4. $ git add /path/to/file/test.js  
  5. # 支持正則表達式  
  6. $ git add ./*.js  
  7. # 添加指定文件到暫存區(qū)  
  8. $ git add [file1] [file2] ...  
  9. # 添加指定目錄到暫存區(qū),包括子目錄  
  10. $ git add [dir]  
  11. # 添加當(dāng)前目錄的所有文件到暫存區(qū)  
  12. $ git add .  
  13. # 添加每個變化前,都會要求確認(rèn)  
  14. # 對于同一個文件的多處變化,可以實現(xiàn)分次提交  
  15. $ git add -p 

刪除

rm 和上面的 add 命令相反,從工作空間中去掉某個文件 

  1. # 移除 HelloWorld.js  
  2. $ git rm HelloWorld.js  
  3. # 移除子目錄中的文件  
  4. $ git rm /pather/to/the/file/HelloWorld.js  
  5. # 刪除工作區(qū)文件,并且將這次刪除放入暫存區(qū)  
  6. $ git rm [file1] [file2] ...  
  7. # 停止追蹤指定文件,但該文件會保留在工作區(qū)  
  8. $ git rm --cached [file] 

分支

管理分支,可以通過下列命令對分支進行增刪改查切換等 

  1. # 查看所有的分支和遠程分支  
  2. $ git branch -a  
  3. # 創(chuàng)建一個新的分支  
  4. $ git branch [branch-name]  
  5. # 重命名分支  
  6. # git branch -m <舊名稱> <新名稱>  
  7. $ git branch -m [branch-name] [new-branch-name]  
  8. # 編輯分支的介紹  
  9. $ git branch [branch-name] --edit-description  
  10. # 列出所有本地分支  
  11. $ git branch  
  12. # 列出所有遠程分支  
  13. $ git branch -r  
  14. # 新建一個分支,但依然停留在當(dāng)前分支  
  15. $ git branch [branch-name]  
  16. # 新建一個分支,并切換到該分支  
  17. $ git checkout -b [branch]  
  18. # 新建一個分支,指向指定commit  
  19. $ git branch [branch] [commit]  
  20. # 新建一個分支,與指定的遠程分支建立追蹤關(guān)系  
  21. $ git branch --track [branch] [remote-branch]  
  22. # 切換到指定分支,并更新工作區(qū)  
  23. $ git checkout [branch-name]  
  24. # 切換到上一個分支  
  25. $ git checkout -  
  26. # 建立追蹤關(guān)系,在現(xiàn)有分支與指定的遠程分支之間  
  27. $ git branch --set-upstream [branch] [remote-branch]  
  28. # 合并指定分支到當(dāng)前分支  
  29. $ git merge [branch]  
  30. # 選擇一個commit,合并進當(dāng)前分支  
  31. $ git cherry-pick [commit]  
  32. # 刪除分支  
  33. $ git branch -d [branch-name]  
  34. # 刪除遠程分支  
  35. $ git push origin --delete [branch-name]  
  36. $ git branch -dr [remote/branch]  
  37. # 切換到某個分支  
  38. $ git co <branch>  
  39. # 創(chuàng)建新的分支,并且切換過去  
  40. $ git co -b <new_branch>  
  41. # 基于branch創(chuàng)建新的new_branch  
  42. $ git co -b <new_branch> <branch> 
  43. # 把某次歷史提交記錄checkout出來,但無分支信息,切換到其他分支會自動刪除  
  44. $ git co $id  
  45. # 把某次歷史提交記錄checkout出來,創(chuàng)建成一個分支  
  46. $ git co $id -b <new_branch>  
  47. # 刪除某個分支  
  48. $ git br -d <branch>  
  49. # 強制刪除某個分支 (未被合并的分支被刪除的時候需要強制)  
  50. $ git br -D <branch> 

檢出

將當(dāng)前工作空間更新到索引所標(biāo)識的或者某一特定的工作空間 

  1. # 檢出一個版本庫,默認(rèn)將更新到master分支  
  2. $ git checkout  
  3. # 檢出到一個特定的分支  
  4. $ git checkout branchName  
  5. # 新建一個分支,并且切換過去,相當(dāng)于"git branch <名字>; git checkout <名字> 
  6. $ git checkout -b newBranch 

遠程同步

遠程同步的遠端分支 

  1. # 下載遠程倉庫的所有變動  
  2. $ git fetch [remote]  
  3. # 顯示所有遠程倉庫  
  4. $ git remote -v  
  5. # 顯示某個遠程倉庫的信息  
  6. $ git remote show [remote]  
  7. # 增加一個新的遠程倉庫,并命名  
  8. $ git remote add [shortname] [url]  
  9. # 查看遠程服務(wù)器地址和倉庫名稱  
  10. $ git remote -v  
  11. # 添加遠程倉庫地址  
  12. $ git remote add origin git@ github:xxx/xxx.git  
  13. # 設(shè)置遠程倉庫地址(用于修改遠程倉庫地址)  
  14. $ git remote set-url origin git@ github.com:xxx/xxx.git  
  15. # 刪除遠程倉庫  
  16. $ git remote rm <repository>  
  17. # 上傳本地指定分支到遠程倉庫  
  18. # 把本地的分支更新到遠端origin的master分支上  
  19. # git push <遠端> <分支>  
  20. # git push 相當(dāng)于 git push origin master  
  21. $ git push [remote] [branch]  
  22. # 強行推送當(dāng)前分支到遠程倉庫,即使有沖突  
  23. $ git push [remote] --force  
  24. # 推送所有分支到遠程倉庫  
  25. $ git push [remote] --all 

撤銷 

  1. # 恢復(fù)暫存區(qū)的指定文件到工作區(qū)  
  2. $ git checkout [file]  
  3. # 恢復(fù)某個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,同時重置暫存區(qū),但工作區(qū)不變  
  12. $ git reset [commit] 
  13. # 重置當(dāng)前分支的HEAD為指定commit,同時重置暫存區(qū)和工作區(qū),與指定commit一致  
  14. $ git reset --hard [commit]  
  15. # 重置當(dāng)前HEAD為指定commit,但保持暫存區(qū)和工作區(qū)不變  
  16. $ git reset --keep [commit]  
  17. # 新建一個commit,用來撤銷指定commit  
  18. # 后者的所有變化都將被前者抵消,并且應(yīng)用到當(dāng)前分支  
  19. $ git revert [commit]  
  20. # 恢復(fù)最后一次提交的狀態(tài)  
  21. $ git revert HEAD  
  22. # 暫時將未提交的變化移除,稍后再移入  
  23. $ git stash  
  24. $ git stash pop  
  25. # 列所有stash  
  26. $ git stash list  
  27. # 恢復(fù)暫存的內(nèi)容  
  28. $ git stash apply  
  29. # 刪除暫存區(qū)  
  30. $ git stash drop 

commit

將當(dāng)前索引的更改保存為一個新的提交,這個提交包括用戶做出的更改與信息 

  1. # 提交暫存區(qū)到倉庫區(qū)附帶提交信息  
  2. $ git commit -m [message]  
  3. # 提交暫存區(qū)的指定文件到倉庫區(qū)  
  4. $ git commit [file1] [file2] ... -m [message]  
  5. # 提交工作區(qū)自上次commit之后的變化,直接到倉庫區(qū)  
  6. $ git commit -a  
  7. # 提交時顯示所有diff信息  
  8. $ git commit -v  
  9. # 使用一次新的commit,替代上一次提交  
  10. # 如果代碼沒有任何新變化,則用來改寫上一次commit的提交信息  
  11. $ git commit --amend -m [message]  
  12. # 重做上一次commit,并包括指定文件的新變化  
  13. $ git commit --amend [file1] [file2] ... 

diff

顯示當(dāng)前工作空間和提交的不同 

  1. # 顯示工作目錄和索引的不同  
  2. $ git diff  
  3. # 顯示索引和最近一次提交的不同  
  4. $ git diff --cached  
  5. # 顯示工作目錄和最近一次提交的不同  
  6. $ git diff HEAD 

grep

可以在版本庫中快速查找

可選配置: 

  1. # 感謝Travis Jeffery提供的以下用法:  
  2. # 在搜索結(jié)果中顯示行號  
  3. $ git config --global grep.lineNumber true  
  4. # 是搜索結(jié)果可讀性更好  
  5. $ git config --global alias.g "grep --break --heading --line-number"  
  6. # 在所有的java中查找variableName  
  7. $ git grep 'variableName' -- '*.java'  
  8. # 搜索包含 "arrayListName" 和, "add" 或 "remove" 的所有行  
  9. $ git grep -e 'arrayListName' --and \( -e add -e remove \) 

log

顯示這個版本庫的所有提交 

  1. # 顯示所有提交  
  2. $ git log  
  3. # 顯示某幾條提交信息  
  4. $ git log -n 10  
  5. # 僅顯示合并提交  
  6. $ git log --merges  
  7. # 查看該文件每次提交記錄  
  8. $ git log <file>  
  9. # 查看每次詳細(xì)修改內(nèi)容的diff  
  10. $ git log -p <file>  
  11. # 查看最近兩次詳細(xì)修改內(nèi)容的diff  
  12. $ git log -p -2  
  13. #查看提交統(tǒng)計信息  
  14. $ git log --stat 

merge

合并就是將外部的提交合并到自己的分支中 

  1. # 將其他分支合并到當(dāng)前分支  
  2. $ git merge branchName  
  3. # 在合并時創(chuàng)建一個新的合并后的提交  
  4. # 不要 Fast-Foward 合并,這樣可以生成 merge 提交  
  5. $ git merge --no-ff branchName 

mv

重命名或移動一個文件 

  1. # 重命名  
  2. $ git mv test.js test2.js  
  3. # 移動  
  4. $ git mv test.js ./new/path/test.js  
  5. # 改名文件,并且將這個改名放入暫存區(qū)  
  6. $ git mv [file-original] [file-renamed]  
  7. # 強制重命名或移動  
  8. # 這個文件已經(jīng)存在,將要覆蓋掉  
  9. $ git mv -f myFile existingFile 

tag 

  1. # 列出所有tag  
  2. $ git tag  
  3. # 新建一個tag在當(dāng)前commit  
  4. $ git tag [tag]  
  5. # 新建一個tag在指定commit  
  6. $ git tag [tag] [commit]  
  7. # 刪除本地tag  
  8. $ git tag -d [tag]  
  9. # 刪除遠程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. # 新建一個分支,指向某個tag  
  18. $ git checkout -b [branch] [tag] 

pull

從遠端版本庫合并到當(dāng)前分支 

  1. # 從遠端origin的master分支更新版本庫  
  2. # git pull <遠端> <分支>  
  3. $ git pull origin master 
  4. # 抓取遠程倉庫所有分支更新并合并到本地,不要快進合并  
  5. $ git pull --no-ff 

ci 

  1. $ git ci <file>  
  2. $ git ci .  
  3. # 將git add, git rm和git ci等操作都合并在一起做  
  4. $ git ci -a  
  5. $ git ci -am "some comments"  
  6. # 修改最后一次提交記錄  
  7. $ git ci --amend 

rebase (謹(jǐn)慎使用)

將一個分支上所有的提交歷史都應(yīng)用到另一個分支上

不要在一個已經(jīng)公開的遠端分支上使用 rebase. 

  1. # 將experimentBranch應(yīng)用到master上面  
  2. # git rebase <basebranch> <topicbranch>  
  3. $ git rebase master experimentBranch 

reset (謹(jǐn)慎使用)

將當(dāng)前的頭指針復(fù)位到一個特定的狀態(tài)。這樣可以使你撤銷 merge、pull、commits、add 等

這是個很強大的命令,但是在使用時一定要清楚其所產(chǎn)生的后果 

  1. # 使 staging 區(qū)域恢復(fù)到上次提交時的狀態(tài),不改變現(xiàn)在的工作目錄  
  2. $ git reset  
  3. # 使 staging 區(qū)域恢復(fù)到上次提交時的狀態(tài),覆蓋現(xiàn)在的工作目錄  
  4. $ git reset --hard  
  5. # 將當(dāng)前分支恢復(fù)到某次提交,不改變現(xiàn)在的工作目錄  
  6. # 在工作目錄中所有的改變?nèi)匀淮嬖?nbsp; 
  7. $ git reset dha78as  
  8. # 將當(dāng)前分支恢復(fù)到某次提交,覆蓋現(xiàn)在的工作目錄  
  9. # 并且刪除所有未提交的改變和指定提交之后的所有提交  
  10. $ git reset --hard dha78as 

其他 

  1. # 生成一個可供發(fā)布的壓縮包  
  2. $ git archive  
  3. # 打補丁  
  4. $ git apply ../sync.patch  
  5. # 測試補丁能否成功  
  6. $ git apply --check ../sync.patch  
  7. # 查看Git的版本  
  8. $ git --version  

 

責(zé)任編輯:龐桂玉 來源: Linux公社
相關(guān)推薦

2020-04-20 10:47:57

Redis數(shù)據(jù)開發(fā)

2017-11-28 15:29:04

iPhone X網(wǎng)頁適配

2020-06-16 10:57:20

搭建

2024-08-28 08:42:21

API接口限流

2016-07-22 15:12:12

Win10技巧重裝

2021-11-19 11:16:29

Git命令Linux

2023-08-26 21:42:08

零拷貝I/O操作

2021-12-27 07:31:37

JavaNeo4J數(shù)據(jù)庫

2021-02-26 10:21:35

比特幣投資金融

2023-07-27 08:26:36

零拷貝I/O操作

2019-05-13 08:24:58

數(shù)據(jù)庫MySQLInnoDB

2021-10-28 19:23:27

界面嵌入式 UI

2024-02-27 08:14:51

Nginx跨域服務(wù)

2024-07-31 08:39:45

Git命令暫存區(qū)

2013-06-09 10:34:24

華為網(wǎng)絡(luò)規(guī)劃企業(yè)ICT

2024-09-09 11:35:35

2020-07-27 07:00:00

超文本鏈接Word文檔網(wǎng)絡(luò)

2020-06-17 11:42:50

異常解析器Spring MVC

2017-11-06 16:30:33

開源

2023-02-07 11:44:02

點贊
收藏

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