GIT常用命令

2021-07-10 21:41:25 字數 3062 閱讀 4150

拷貝乙個遠端倉庫

git clone **

檢視當前分支狀態

git status

提交所有 的修改到暫存區域

git add .

提交修改

git add readme

新增readme檔案

git add readme test.rb license

提交多個檔案

git commit -m 「修改說明」 – 提交

git commit -a -m 『added new benchmarks』 - 跳轉使用暫存區,直接 提交

git commit –amend 撤消提交 操作

更新 git pull

合併 0.1.1分支 到當前 分支

git merge 0.1.1

git tag v1.4 #打標籤

git的分支操作:

1.檢視本地和遠端分支

git branch -a

2.檢視本地分支

git branch

3.建立分支

git branch test

4.切換分支 到test

git checkout test

5.建立 並切換 到分支

git checkout -b test2

6.刪除 本地分支

git brandh -d test2

配置命令 git config

git config –global user.name 「john doe」 – 預設使用者名稱

git config –global user.email [email protected] – 預設使用者郵箱

git config –global core.editor emacs –預設的編輯 器設定,預設是vim

git config –list –列出所有 的設定,同乙個屬性可能 有多個值 ,因為多次設定,以最後 乙個設定為準

git config 檢視具體的設定

通過 config 設定git 別名

git config –global alias.co checkout

git config –global alias.br branch

git config –global alias.ci commit

git config –global alias.st status

取消暫存

git config –global alias.unstage 『reset head –』

顯示最後一次提交資訊

git config –global alias.last 『log -1 head』

呼叫gitk

git config –global alias.visual 『!gitk』

移除檔案

git rm – 移除檔案

git rm -f – 如果刪除之前修改過並且已經放到暫存區域的話,則必須要用強制刪除選項 -f(譯註:即 force 的首字母)

git rm –cached readme –從git倉庫中刪除 ,但是本地保留,不再跟蹤

支援glob 模式模式:

git rm log/*.log

git rm *~

其他git init –初始化當前目前 為git專案 (在現有目錄中初始化倉庫)

git log – 檢視提交 歷史

git log -p -2 – 每次提交 的**差異,只顯示最近2次提交

git log –stat –每次提交的簡略的統計資訊

git log –pretty=oneline 將每個提交放在一行顯示,檢視的提交數很大時非常有用

git log –pretty=format:」%h - %an, %ar : %s」 – 格式化輸出

git log –pretty=format:」%h %s」 –graph – 圖形化顯示

git reset head contributing.md – 取消暫存檔案

git checkout – contributing.md – 撤消對檔案的修改

git remote –檢視遠端倉庫

git remote -v –如果你的遠端倉庫不止乙個,該命令會將它們全部列出 (實際是乙個fetch,乙個push)

git remote add 新增遠端倉庫

git remote add pb https://… (git fetch pb, 獲取別的倉庫內容 )

同乙個專案,可能會有多個遠端倉庫的url

(每個開發者可能把分支部署到自己的伺服器上)

git remote show origin – 檢視更詳細 的資訊

git remote rename pb paul – 遠端倉庫的重新命名

git remote rm paul – 遠端倉庫的移除

git pull –設定了分支跟蹤某個遠端分支

抓取資料後會嘗試合併到當前所在的分支

git fetch不會自動合併

git tag – 列表所有的標籤

git tag -l 『v1.8.5*』 使用特定的模式查詢標籤

git tag v1.4-lw –建立輕量標籤(lightweight)

git tag -a v1.4 -m 『my version 1.4』 – 建立 附註標籤(annotated) (-a - 新增乙個附註標籤,-m 選項指定了一條將會儲存在標籤中的資訊)

git tag -a v1.2 9fceb02 –後期打標籤 ,把v1.2提交 ,加在相應的commit上

commit的md5碼可以 使用 git log –pretty=oneline 查詢 到

git push origin [tagname] – 共享標籤

git push origin –tags

git checkout -b [branchname] [tagname] – 檢出 標籤

git show –顯示 標籤資訊,對應的提交 資訊

git show v1.2 –檢視 v1.2的提交資訊

常用命令 Git 常用命令大全

安裝教程可參照 廖雪峰老師的安裝教程。git config 在git中,使用git config 命令來配置 git 的配置檔案,git配置級別主要有3類 1 倉庫級別 local 本地 git 倉庫級別配置檔案,作用於當前倉庫。優先順序最高 2 使用者級別 global,全域性配置檔案,作用於所有...

git 常用命令

檢視是否存在檔案需要上傳 git status git add git commit m 建立遠端倉庫 git remote add origin 116.255.146.153 ruby cd work daily project.git 更新git fetch 116.255.146.153 r...

git常用命令

詳細 1,git log p 命令來顯示每一次提交與其父節點提交內容之間快照的差異。2,為了檢視載入 staged 而並未提交 not committed 的內容差異,可以使用 git diff stage 命令 在git 1.6之前的版本中,使用 cached 適應情形 在執行git commit...