git的常用命令

2021-08-30 13:46:50 字數 3170 閱讀 8245

日期: 2023年12月 9日

珠峰培訓

我每天使用 git ,但是很多命令記不住。

一般來說,日常使用只要記住下圖6個命令,就可以了。但是熟練使用,恐怕要記住60~100個命令。

下面是我整理的常用 git 命令清單。幾個專用名詞的譯名如下。

workspace:工作區

index / stage:暫存區

repository:倉庫區(或本地倉庫)

remote:遠端倉庫

一、新建**庫

$ git init

$ git init [project-name]

$ git clone [url]

二、配置

git的設定檔案為.gitconfig,它可以在使用者主目錄下(全域性配置),也可以在專案目錄下(專案配置)。

$ git config --list

$ git config -e [–global]

$ git config [–global] user.name 「[name]」

$ git config [–global] user.email 「[email address]」

三、增加/刪除檔案

$ git add [file1] [file2] …

$ git add [dir]

$ git add .

$ git add -p

$ git rm [file1] [file2] …

$ git rm --cached [file]

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

四、**提交

$ git commit -m [message]

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

$ git commit -a

$ git commit -v

$ git commit --amend -m [message]

$ git commit --amend [file1] [file2] …

五、分支

$ git branch

$ git branch -r

$ git branch -a

$ git branch [branch-name]

$ git checkout -b [branch]

$ git branch [branch] [commit]

$ git branch --track [branch] [remote-branch]

$ git checkout [branch-name]

$ git checkout -

$ git branch --set-upstream [branch] [remote-branch]

$ git merge [branch]

$ git cherry-pick [commit]

$ git branch -d [branch-name]

$ git push origin --delete [branch-name]

$ git branch -dr [remote/branch]

六、標籤

$ git tag

$ git tag [tag]

$ git tag [tag] [commit]

$ git tag -d [tag]

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

$ git show [tag]

$ git push [remote] [tag]

$ git push [remote] --tags

$ git checkout -b [branch] [tag]

七、檢視資訊

$ git status

$ git log

$ git log --stat

$ git log -s [keyword]

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

$ git log [tag] head --grep feature

$ git log --follow [file]

$ git whatchanged [file]

$ git log -p [file]

$ git log -5 --pretty --oneline

$ git shortlog -sn

$ git blame [file]

$ git diff

$ git diff --cached [file]

$ git diff head

$ git diff [first-branch]…[second-branch]

$ git diff --shortstat 「@」

$ git show [commit]

$ git show --name-only [commit]

$ git show [commit]:[filename]

$ git reflog

八、遠端同步

$ git fetch [remote]

$ git remote -v

$ git remote show [remote]

$ git remote add [shortname] [url]

$ git pull [remote] [branch]

$ git push [remote] [branch]

$ git push [remote] --force

$ git push [remote] --all

九、撤銷

$ git checkout [file]

$ git checkout [commit] [file]

$ git checkout .

$ git reset [file]

$ git reset --hard

$ git reset [commit]

$ git reset --hard [commit]

$ git reset --keep [commit]

$ git revert [commit]

$ git stash

$ git stash pop

十、其他

$ git archive

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