Git 速查表 - 常用命令快速参考
免费在线 Git 速查表,按分类整理的可搜索命令参考。快速查找分支、合并、变基、暂存、重置等 Git 命令。
Setup & Config
git initInitialize a new Git repository in the current directory
git clone <url>Clone a remote repository to your local machine
git config user.name "<name>"Set the author name for commits
git config user.email "<email>"Set the author email for commits
Staging & Commits
git add <file>Stage a file for the next commit
git commit -m "<message>"Create a commit with a message
git statusShow the working tree status
git diffShow unstaged changes
git logShow commit history
Branching & Merging
git branchList, create, or delete branches
git checkout <branch>Switch to a branch or restore files
git switch <branch>Switch to a branch (modern alternative to checkout)
git merge <branch>Merge a branch into the current branch
git rebase <branch>Reapply commits on top of another branch
Remote
git remote -vList remote repositories with URLs
git fetchDownload objects and refs from a remote
git pullFetch and integrate changes from a remote branch
git pushUpload local commits to a remote repository
Stash
git stashTemporarily save uncommitted changes
git stash popApply the most recent stash and remove it from the list
git stash listList all stashed changes
git stash dropRemove a specific stash entry
git stash applyApply a stash without removing it from the list
Undo & Reset
git reset <file>Unstage a file while preserving changes
git revert <commit>Create a new commit that undoes a previous commit
git restore <file>Discard changes in the working directory
git clean -fdRemove untracked files and directories
Inspection
git log --onelineShow compact commit history (one line per commit)
git log --graph --allVisualize branch history as a graph
git show <commit>Display details and diff of a specific commit
git blame <file>Show who last modified each line of a file
git reflogShow a log of all reference updates (useful for recovery)
git shortlog -snSummarize commit counts by author
Tags
git tag <name>Create a lightweight tag at the current commit
git tag -a <name> -m "<msg>"Create an annotated tag with a message
git tag -lList all tags
git push origin <tag>Push a specific tag to a remote
git tag -d <name>Delete a local tag
什么是 Git 速查表?
Git 速查表是一份按分类整理的常用 Git 命令快速参考指南。Git 是全球最流行的分布式版本控制系统,被数百万开发者用于跟踪变更、协作开发和管理项目历史。面对数十个命令和数百个选项,即使是经验丰富的开发者也需要一份简洁的参考。本速查表涵盖了从基本设置和暂存到交互式变基、存储管理和历史检查等高级工作流程。
如何使用 Git 速查表
- 浏览按分类整理的命令:设置、暂存、分支、远程、储藏、撤销、检查和标签。
- 使用搜索框按关键词过滤命令——输入 'rebase'、'stash'、'reset' 或命令和描述的任何部分。
- 每个命令显示语法、简短描述和常用标志或选项。
- 点击任意命令旁边的复制按钮,将其复制到剪贴板以便在终端中使用。
- 使用每个命令下方列出的标志来发现你可能不知道的有用变体。
常见使用场景
- 日常开发工作流 — 在日常开发工作流中快速查找提交、分支和推送代码的命令,无需离开浏览器。
- 学习 Git — Git 新手?浏览有组织的分类来发现命令并了解每个命令的作用,包括常用标志和选项。
- 解决合并冲突 — 在需要解决冲突或撤销错误时,找到正确的变基、合并、重置和还原命令。
- 代码审查与检查 — 使用 git log、git blame 和 git show 等检查命令来审查提交历史、理解变更并追踪代码作者。