Git 常用命令

2021-08-18 11:43:40 字數 2152 閱讀 9669

建立版本庫

命令說明

git clone

轉殖遠端版本庫

git init

初始化本地版本庫

git remote add

增加遠端版本庫

git config --global user.name 「***」

配置使用者名稱

git config --global user.email 「***@***.com」

配置郵件

add命令

說明git add .

將當前目錄下所有檔案增加git版本控制,包括子目錄

git add

將指定目錄下的檔案增加git版本控制,包括子目錄

git add

將指定檔案增加git版本控制

commit

命令說明

git commit -m

提交暫存區到本地倉庫,message代表說明資訊

git commit -m

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

git commit --amend -m

使用一次新的commit,替代上一次提交

git revert

撤銷指定的提交

git reset <–hard/soft>

刪除指定的提交

【例】:如果想徹底刪除本地最近一次提交記錄,並同步到**倉庫:

git reset --hard head^

git push origin master -f

branch

命令說明

git branch

列出所有本地分支

git branch -r

列出所有遠端分支

git branch -a

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

git branch

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

git checkout -b

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

git checkout

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

git branch -d

刪除本地分支

git push --delete

刪除遠端分支

push

命令說明

git push

上傳本地指定[分支/標籤]到遠端倉庫

git push --force

強行推送當前分支到遠端倉庫,即使有衝突

git push --all

推送所有分支到遠端倉庫

git push --tags

推送所有標籤到遠端倉庫

【注】:預設是origin,

預設是master

pull

命令說明

git fetch

從遠端倉庫獲取最新**(不會自動merge)

git merge

合併指定分支

git pull

tag命令

說明git tag

列出所有本地標籤

git tag

基於最新提交建立標籤

git checkout

切換到指定標籤

git tag -d

刪除本地標籤

git push :refs/tags/

刪除遠端標籤

遠端倉庫位址切換/修改

命令說明

git remote -v

檢視遠端倉庫的位址

git remote set-url origin

更換遠端倉庫位址,url為新位址

git remote rm origin

刪除現有遠端倉庫

git remote add origin

新增新遠端倉庫

其他命令

命令說明

git status

顯示有變更的檔案

git log

顯示當前分支的版本歷史

git diff

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

git diff head

顯示工作區與當前分支最新commit之間的差異

git cherry-pick

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

常用命令 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...