Git常用命令及方法大全

2022-08-14 07:27:09 字數 3054 閱讀 1366

workspace:工作區

index / stage:暫存區

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

remote:遠端倉庫

一、新建**庫

$ git clone [url]

二、配置

$ 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常用命令及方法大全

本地分支關聯遠端 git branch set upstream to origin 分支名 分支名 庫修改密碼後push不上去怎麼辦?重新輸入密碼 git config system unset credential.helper 密碼儲存同步 git config global credenti...

常用命令 Git 常用命令大全

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

Git常用命令大全

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