Git常見命令總結

2021-08-23 14:07:13 字數 3053 閱讀 5562

$ git init

在當前目錄新建乙個git**庫

$ git init [project-name]

新建乙個目錄,將其初始化為git**庫

$ git add [file1] [file2]

新增指定檔案到暫存區

$ git add [dir]

新增指定目錄到暫存區,包括子目錄

$ git rm [file1] [file2]

刪除工作區檔案,並且將這次刪除放入暫存區

$ git mv [file-original] [file-renamed]

改名檔案,並且將這個改名放入暫存區

$ git commit -m [message]

提交暫存區到倉庫區

$ git commit [file1] [file2] … -m [message]

提交暫存區的指定檔案到倉庫區

$ git commit -a

提交工作區自上次commit之後的變化,直接到倉庫區

$ git commit –amend [file1] [file2]

重做上一次commit,幷包括指定檔案的新變化

$ git branch

列出所有本地分支

$ git branch -r

列出所有遠端分支

$ git branch -a

列出所有本地分支和遠端分支

$ git branch [branch-name]

新建乙個分支,但依然停留在當前分支

$ git checkout -b [branch]

新建乙個分支,並切換到該分支

$ git branch [branch] [commit]

新建乙個分支,指向指定commit

$ git checkout [branch-name]

切換到指定分支,並更新工作區

$ git checkout

切換到上乙個分支

$ git merge [branch]

合併指定分支到當前分支

$ git cherry-pick [commit]

選擇乙個commit,合併進當前分支

$ git branch -d [branch-name]

刪除分支

$ git push origin –delete [branch-name]

刪除遠端分支

$ git tag

列出所有tag

$ git tag [tag]

新建乙個tag在當前commit

$ git tag [tag] [commit]

新建乙個tag在指定commit

$ git tag -d [tag]

刪除本地tag

$ git push origin :refs/tags/[tagname]

刪除遠端tag

$ git show [tag]

檢視tag資訊

$ git push [remote] [tag]

提交指定tag

$ git push [remote] –tags

提交所有tag

$ git checkout -b [branch] [tag]

新建乙個分支,指向某個tag

$ git status

顯示有變更的檔案

$ git log

顯示當前分支的版本歷史

$ git log –stat

顯示commit歷史,以及每次commit發生變更的檔案

$ git log [tag] head –pretty=format:%s

顯示某個commit之後的所有變動,每個commit佔據一行

$ git log [tag] head –grep feature

顯示某個commit之後的所有變動,其」提交說明」必須符合搜尋條件

$ git log -p [file]

顯示指定檔案相關的每一次diff

$ git log -5 –pretty –oneline

顯示過去5次提交

$ git shortlog -sn

顯示所有提交過的使用者,按提交次數排序

$ git blame [file]

顯示指定檔案是什麼人在什麼時間修改過

$ git diff

顯示暫存區和工作區的差異

$ git show [commit]:[filename]

顯示某次提交時,某個檔案的內容

$ git reflog

顯示當前分支的最近幾次提交

$ git remote -v

顯示所有遠端倉庫

$ git remote show [remote]

顯示某個遠端倉庫的資訊

$ git remote add [shortname] [url]

增加乙個新的遠端倉庫,並命名

$ git pull [remote] [branch]

取回遠端倉庫的變化,並與本地分支合併

$ git push [remote] [branch]

上傳本地指定分支到遠端倉庫

$ git push [remote] –all

推送所有分支到遠端倉庫

$ git checkout [file]

恢復暫存區的指定檔案到工作區

$ git checkout [commit] [file]

恢復某個commit的指定檔案到暫存區和工作區

$ git checkout

恢復暫存區的所有檔案到工作區

$ git reset [file]

重置暫存區的指定檔案,與上一次commit保持一致,但工作區不變

$ git reset –hard

重置暫存區與工作區,與上一次commit保持一致

$ git reset [commit]

重置當前分支的指標為指定commit,同時重置暫存區,但工作區不變

$ git archive

生成乙個可供發布的壓縮包

git常見命令總結

git help xx 顯示xx的help git add filename 將工作檔案修改提交到本地暫存區 git add 將所有修改過的工作檔案提交暫存區 git rm filename 從版本庫中刪除檔案 git rm filename cached 從版本庫中刪除檔案,但不刪除檔案 git ...

Git常見命令總結

git add 檔名 新增檔案 git commit m 說明 提交檔案 git rm 檔名 刪除版本庫里檔案 git diff 檢視difference git diff head 檔名 檢視工作區於與版本庫檔案的不同 git status 檢視狀態 git log 提交日誌 git reset ...

Git常見命令總結

簡介 git是一種分布式版本控制系統 集中式 svn git init 建立本地git倉庫 git add 新增檔案 git commit m 提交,m後語句為提交說明 git status 檢視倉庫當前狀態 git diff 檢視檔案 進行了修改 git log pretty oneline 顯示...