Git 詳細命令大全

2021-09-19 09:37:10 字數 2215 閱讀 2575

建立版本庫

建立目錄 mkdir [dirctory]

切換目錄 cd [directory]

顯示當前目錄 pwd

把當前目錄變成git倉庫 git init

**提交

新增特定檔案到暫存區 git add [file]

新增特定資料夾所有檔案到暫存區 git add .

提交檔案到倉庫 git commit -m [message]

檢視資訊

檢視狀態 git status

檢視修改 git diff

檢視版本提交歷史 git log

檢視命令歷史 git reflog

檢視檔案內容 cat [file]

**撤銷

撤銷未新增到暫存區的修改 git checkout – [file]

撤銷已新增到暫存區的修改

git reset head [file]

git checkout – [file]

撤銷提交到版本庫的修改 版本回退

刪除檔案

刪除工作區的檔案 rm [file]

刪除工作區檔案後有兩個選擇:

(1)刪除版本庫的檔案

git rm [file]

git commit -m [message]

(2)版本庫的檔案恢復工作區檔案

git checkout – [file]

版本回退

回退到上1個版本 git reset – hard head^

回退到上上個版本 git reset – hard head^^

回退到特定版本 git reset – hard [版本號]

分支操作

檢視分支 git branch

建立分支 git branch [name]

切換分支 git checkout [name]

建立+切換分支 git checkout -b [name]

刪除分支 git branch -d [name]

強制刪除分支 git branch -d [name]

合併分支

刪除被合併分支的資訊 git merge [name]

新建立commit&保留被合併分支的資訊 git merge --no-ff -m 「message」 [name]

合併衝突:

(1)當不同的2個分支同時對乙個地方進行不同的修改,git無法自動合併

(2)手動修改,再提交,就合併成功。

遠端庫操作1

檢視遠端庫資訊 git remote -v

替換遠端庫名稱 git remote rename [origin] [destination]

刪除遠端庫及其引用 git remote rm [destination]

遠端庫操作2

本地推送分支(修改)到遠端庫 git push origin [branch-name]

本地從遠端庫拉取分支 git pull origin [branch-name]

設定本地分支與遠端分支的鏈結

git branch --set-upstream-to [branch-name] origin/[branch-name]

建立標籤

建立標籤 git tag [tagname]

給指定的commit建立標籤 git tag -a [tagname] -m 「message」 [commit的id名]

檢視所有標籤 git tag

推送乙個本地標籤 git push origin [tagname]

推送全部未推送的本地標籤 git push origin --tags

刪除乙個本地標籤 git tag -d [tagname]

刪除乙個遠端標籤

(1)先把本地標籤刪除

(2)再刪除遠端標籤 git push origin :refs/tags/[tagname]

儲存工作區狀態

Git 命令大全

git 的特點 1.關注檔案的整體變化 2.git 更像是把變化的檔案作快照後,記錄在乙個微型的檔案系統中。每次提交更新時,它會縱覽一遍所有檔案的指紋資訊並對檔案作一快照,然後儲存乙個指向這次快照 的索引。為提高效能,若檔案沒有變化,git 不會再次儲存,而只對上次儲存的快照作一鏈結。基本的 git...

git命令大全

公司使用了github 特意從網上總結下常用的git命令,備用 1 遠端倉庫相關命令 檢出倉庫 git clone git 首次開發必用 檢視遠端倉庫 git remote v 新增遠端倉庫 git remote add name url 刪除遠端倉庫 git remote rm name 修改遠端...

git命令大全

git 是乙個很強大的分布式版本控制系統。它不但適用於管理大型開源軟體的源 管理私人的文件和源 也有很多優勢。git常用操作命令 1 遠端倉庫相關命令 檢出倉庫 git clone git 檢視遠端倉庫 git remote v 新增遠端倉庫 git remote add name url 刪除遠端...