git 常用命令

2021-10-22 17:53:42 字數 3747 閱讀 7466

git 導圖

#在當前目錄新建git**庫

git int

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

git init [project name]

git clone [url]

複製

git 的設定檔案為.gitconfig, 它可以在使用者的主目錄下,也可以在專案目錄下。

#顯示當前的git配置

git config --list

#編輯git配置檔案

git config -e [--global]

#設定**提交的使用者資訊

git config [--global] user.name yourname

git config [--global] user.email youremail

複製

#新增指定檔案到暫存區

git add [file]

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

git add [dir]

#刪除工作區檔案,並且將這次刪除放入快取區

git rm [file1] [file2]

#停止追蹤指定檔案,但檔案會保留在工作區

git rm --cached [file1]

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

git mv [file-origin] [file-renamed]

複製

#提交暫存區到倉庫區

git commmit -m [message]

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

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

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

git commit -a

#提交時顯示所有的diff資訊

git commit -v

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

#如果**沒有任何變化,則用來改寫上一次的commit的提交資訊

git commit --amend -m [message]

複製

#列出所有本地分支

git branch

#列出所有遠端分支

git branch -r

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

git branch -a

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

git branch [branch-name]

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

git checkout -b [branch-name]

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

git branch [branch-name] [commit]

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

git checkout [branch-name]

#切換到上乙個分支

git checkout -

#合併指定分支到當前分支

git merge [branch-name]

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

git cherry-pick [commit]

#刪除分支

git branch -d [branch-name]

#刪除遠端分支

git push origin --delete [branch-name]

git branch -dr [remote/branch]

複製

#列出所有tag

git tag

#新建乙個tag在當前的commit

git tag [tag-name]

#新建乙個tag

git tag -a v1.0 -m "我的第乙個版本"

#刪除本地tag

git tag -d [tag]

#檢視tag資訊

git show [tag]

#提交指定tag

git push [remote] [tag]

#提交所有tag

git push [remote] --tags

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

git checkout -b [branch] [tag]

複製

#顯示有變更的檔案

git status

#顯示當前分支的版本歷史

git log

git log -s [keyword]

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

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

#顯示過去5次提交

git log -5 --pretty --oneline

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

git shortlog -sn

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

git diff

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

git diff head

#顯示兩次提交之間的差異

git diff [first-commit] [second-commit]

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

git reflog

複製

git fetch [remote]

#顯示所有遠端倉庫

git remote -v

#增加乙個新的遠端倉庫,並命名,如 git remote add origin [url]

git remote add [shortname] [url]

#刪除乙個遠端倉庫

git remote remove origin

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

git pull [remote] [branch]

#上傳本地分支到遠端倉庫

git push [remote] [branch]

#強制推送,如 git push -u origin master

git push -u [remote] [branch]

#推送所有分支到遠端倉庫

git push [remote] --all 複製

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

git checkout [file]

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

git checkout

複製

#回滾到某一次提交

git log

git reset --hard head^

如:git reset --hard obfafd(commit id的前幾位)

#回滾後推送給到遠端倉庫

git push -f

複製

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

git archive

複製

參考:常用 git 命令清單

git –everything-is-local

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