Git 速查表
可搜索、可打印的 Git 参考手册——配置、分支、合并、变基、远程仓库、暂存、标签以及撤销更改。免费。
Setup & config
10git config --global user.name "Jane Doe"
Set the name attached to your commits
git config --global user.email "jane@example.com"
Set the email attached to your commits
git config --global init.defaultBranch main
Make new repos start on a "main" branch
git config --global core.editor "code --wait"
Use VS Code as the default Git editor
git config --global pull.rebase true
Rebase instead of merge when pulling
git config --global alias.co checkout
Create a shortcut alias (git co)
git config --global --list
List all global configuration values
git config user.email
Print the email for the current repo
git config --global color.ui auto
Enable colored command-line output
git help <command>
Open the manual page for a command
Create & clone repos
9git init
Initialize a new repo in the current folder
git init my-project
Create a new repo in a new directory
git clone https://example.com/repo.git
Clone a remote repo over HTTPS
git clone git@example.com:user/repo.git
Clone a remote repo over SSH
git clone <url> my-dir
Clone into a specific directory name
git clone --depth 1 <url>
Shallow clone with only the latest commit
git clone --branch dev <url>
Clone and check out a specific branch
git clone --recurse-submodules <url>
Clone and initialize all submodules
git remote add origin <url>
Attach a remote to an existing local repo
Staging & committing
11git add file.txt
Stage a single file for the next commit
git add .
Stage all changes in the current directory
git add -A
Stage all changes including deletions
git add -p
Interactively stage selected hunks
git commit -m "Add login form"
Commit staged changes with a message
git commit -am "Fix typo"
Stage tracked files and commit in one step
git commit --amend
Edit the most recent commit
git commit --amend --no-edit
Add staged changes to the last commit
git rm file.txt
Remove a file and stage the deletion
git mv old.txt new.txt
Rename or move a file and stage it
git reset file.txt
Unstage a file but keep its changes
Branches
10git branch
List all local branches
git branch -a
List local and remote-tracking branches
git switch -c feature/login
Create a new branch and switch to it
git switch main
Switch to an existing branch
git checkout -b hotfix
Classic way to create and switch branches
git branch -m old-name new-name
Rename a branch
git branch -d feature/login
Delete a merged local branch
git branch -D feature/login
Force-delete an unmerged local branch
git push origin --delete feature/login
Delete a branch on the remote
git switch -
Switch back to the previous branch
Merging & rebasing
10git merge feature/login
Merge a branch into the current one
git merge --no-ff feature/login
Merge and always create a merge commit
git merge --squash feature/login
Combine a branch into one staged change
git merge --abort
Cancel a merge with conflicts
git rebase main
Replay current branch commits onto main
git rebase -i HEAD~3
Interactively edit the last 3 commits
git rebase --continue
Resume a rebase after resolving conflicts
git rebase --abort
Cancel an in-progress rebase
git cherry-pick <hash>
Apply a single commit onto the current branch
git mergetool
Launch a tool to resolve merge conflicts
Remotes & syncing
11git remote -v
List configured remotes and their URLs
git remote add upstream <url>
Add a second remote named upstream
git remote set-url origin <url>
Change the URL of an existing remote
git fetch
Download remote changes without merging
git fetch --all --prune
Fetch all remotes and drop stale branches
git pull
Fetch and integrate remote changes
git pull --rebase
Pull and rebase local commits on top
git push
Upload local commits to the remote
git push -u origin main
Push and set the upstream tracking branch
git push --force-with-lease
Safely force-push without clobbering others
git push origin --tags
Push all local tags to the remote
Inspecting & comparing
10git status
Show staged, unstaged, and untracked files
git status -s
Show status in a compact short format
git diff
Show unstaged changes against the index
git diff --staged
Show changes staged for the next commit
git diff main..feature
Compare two branches
git diff HEAD~1 HEAD
Compare the last commit with its parent
git show <hash>
Show the details and diff of one commit
git show HEAD:file.txt
Show a file as it was in a commit
git log --stat
Show commits with changed-file summaries
git shortlog -sn
Count commits grouped by author
Undoing changes
10git restore file.txt
Discard unstaged changes in a file
git restore --staged file.txt
Unstage a file but keep its changes
git restore --source=HEAD~1 file.txt
Restore a file from an earlier commit
git checkout -- file.txt
Classic way to discard local changes
git reset --soft HEAD~1
Undo last commit, keep changes staged
git reset --mixed HEAD~1
Undo last commit, keep changes unstaged
git reset --hard HEAD~1
Undo last commit and discard changes
git revert <hash>
Create a new commit that undoes a commit
git clean -fd
Delete untracked files and directories
git clean -nd
Preview what clean would remove
Stashing
10git stash
Save uncommitted changes and clean the tree
git stash push -m "wip"
Stash changes with a descriptive message
git stash -u
Stash including untracked files
git stash list
List all stashed change sets
git stash show -p
Show the diff of the latest stash
git stash apply
Reapply the latest stash and keep it
git stash pop
Reapply the latest stash and drop it
git stash apply stash@{2}
Reapply a specific stash by index
git stash drop stash@{0}
Delete a single stash entry
git stash clear
Delete all stash entries
Tags
9git tag
List all tags
git tag v1.0.0
Create a lightweight tag at HEAD
git tag -a v1.0.0 -m "Release 1.0.0"
Create an annotated tag with a message
git tag -a v1.0.0 <hash>
Tag a specific past commit
git show v1.0.0
Show details for a tag
git push origin v1.0.0
Push a single tag to the remote
git push origin --tags
Push all local tags to the remote
git tag -d v1.0.0
Delete a tag locally
git push origin --delete v1.0.0
Delete a tag on the remote
Logs & history
12git log
Show the full commit history
git log --oneline
Show a compact one-line-per-commit log
git log --oneline --graph --all
Visualize branches as an ASCII graph
git log -p
Show commit history with diffs
git log --author="Jane"
Filter history by author
git log --since="2 weeks ago"
Filter history by date range
git log --pretty=format:"%h %an %s"
Customize the log output format
git blame file.txt
Show who last changed each line
git reflog
Show the history of where HEAD has been
git bisect start
Begin a binary search for a bad commit
git bisect good <hash>
Mark a commit as known-good during bisect
git bisect bad
Mark the current commit as bad
没有条目匹配“:q”。
关于 Git 速查表
这份 Git 命令速查表按任务组织版本控制知识:设置和配置、创建与克隆仓库、暂存和提交、分支、合并与变基、远程仓库和同步、查看和比较、撤销更改、暂存(stash)、标签,以及日志和历史记录。
各章节的划分方式贴合 Git 问题在实际中出现的方式——"我要怎么撤销这个?""我要怎么移动这个分支?""这些提交之间到底改了什么?"——因此你需要的命令就紧挨着它的各种变体,每一条都附有一句话说明其作用和使用场景。
本速查表免费,完全在客户端运行。用搜索框实时过滤每条命令,通过粘性目录在各章节间跳转,一键复制任意命令,并打印本页——光是撤销那一节,就值得贴在墙上。
如何使用 Git 速查表
- 浏览这十一个章节,从「设置与配置」经「撤销更改」到「日志与历史」。
- 搜索 rebase、stash 或 amend 等任务,即可实时过滤命令。
- 通过粘性侧边栏跳转到「远程仓库与同步」等章节。
- 点击命令或其复制图标进行复制,运行前先调整分支名或远程名。
- 打印速查表,获得一份离线的 Git 参考。
常见问题
共十一个章节:设置和配置、创建与克隆、暂存和提交、分支、合并与变基、远程仓库和同步、查看和比较、撤销更改、暂存(stash)、标签,以及日志和历史记录。
可以。专门的「撤销更改」章节把 reset、restore 和 revert 的不同用法并排列出并附有说明,让你能根据自己的情况选择合适的一个,而不是靠猜。
是的。合并与变基章节展示了这两种工作流及其常见变体,分支和远程仓库章节则涵盖了移动工作内容所需的相关命令。
可以。点击命令或悬停时出现的复制图标,它就会直接进入剪贴板——只需替换成你自己的分支、远程或提交引用。
是的,完全免费——可以在浏览器中搜索,可以打印,并且无需账户即可使用。
热门搜索
git 速查表
git 命令列表
git rebase 和 merge 的区别
git 撤销上次提交
git reset 和 revert 的区别
git stash 命令
git 分支命令
git log 选项
需要帮助?
使用此工具时遇到问题?请告诉我们的团队。