WeTools

Git 速查表

常用 Git 命令分类速查(提交、分支、远程、撤销、变基等)。

本地处理

初始化 & 克隆

git init
git clone <url>
git clone --depth 1 <url>
git clone -b <branch> <url>

查看状态 & 历史

git status
git status -s
git log
git log --oneline --graph --all
git log -p <file>
git log --since="2 weeks ago"
git show <commit>
git blame <file>
git reflog

暂存 & 提交

git add <file>
git add .
git add -p
git commit -m "msg"
git commit --amend
git commit --amend --no-edit
git restore --staged <file>
git restore <file>

分支

git branch
git branch -a
git branch <name>
git switch <branch>
git switch -c <branch>
git branch -d <branch>
git branch -D <branch>
git branch -m <new>
git merge <branch>
git merge --squash <branch>

远程仓库

git remote -v
git remote add origin <url>
git remote set-url origin <url>
git fetch
git pull
git pull --rebase
git push
git push -u origin <branch>
git push --tags
git push origin --delete <branch>

变基 & 樱桃挑选

git rebase <branch>
git rebase -i HEAD~3
git rebase --continue
git rebase --abort
git cherry-pick <commit>
git cherry-pick <a>..<b>

撤销 & 救命

git reset --soft HEAD~1
git reset --mixed HEAD~1
git reset --hard HEAD~1
git revert <commit>
git clean -fd
git stash
git stash pop
git stash list
git stash drop

标签

git tag
git tag <name>
git tag -a v1.0.0 -m "release"
git tag -d <name>
git push origin <tag>
git push origin --delete <tag>

配置 & 别名

git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main
git config --global core.editor "code --wait"
git config --global alias.st status
git config --global alias.lg "log --oneline --graph --all"

相关工具