Git 命令参考

收录日常开发最常用的 Git 子命令:初始化、克隆、分支、合并、stash 与远程操作。支持搜索与一键复制,适合新手入门与老手偶尔忘命令时查阅。

隐私提示:本地解析,不上传服务器。

↓ 在下方输入区粘贴内容,结果会立即显示

常用 Git 命令速查; 搜索命令或说明,一键复制。

git init

Initialize a new repository

git clone <url>

Clone a remote repository

git status

Show working tree status

git add <file>

Stage changes

git add .

Stage all changes

git commit -m "msg"

Commit staged changes

git push

Push commits to remote

git pull

Fetch and merge remote changes

git branch

List branches

git branch <name>

Create a branch

git checkout <branch>

Switch branch

git switch <branch>

Switch branch (newer)

git merge <branch>

Merge branch into current

git log --oneline

Compact commit history

git diff

Show unstaged diff

git stash

Stash working changes

git stash pop

Apply latest stash

git remote -v

List remotes

git fetch

Download remote objects

git rebase <branch>

Rebase onto branch

注释说明

说明

收录日常开发最常用的 Git 子命令; 完整选项见 git help 与官方文档。

收录日常开发最常用的 Git 子命令:初始化、克隆、分支、合并、stash 与远程操作。支持搜索与一键复制,适合新手入门与老手偶尔忘命令时查阅。

快速开始

  1. 浏览列表

    按使用频率整理的常用命令。

  2. 搜索

    按命令名或说明过滤。

  3. 复制命令

    粘贴到终端执行。

与 git help 的关系

本页是速查表; 完整选项与参数说明请运行 git help <command>。

典型工作流

从克隆仓库开始:`git clone <url>` 将远程代码完整复制到本地。日常开发中,用 `git checkout -b feature-x` 创建新分支隔离修改。完成功能后,`git add .` 暂存所有变更,`git commit -m "message"` 提交,最后 `git push origin feature-x` 推送分支。

遇到紧急bug时,用 `git stash` 临时保存未提交的修改并清空工作区,切换到主分支修复。合并时,`git merge --no-ff` 保留分支历史,冲突用 `git mergetool` 可视化解决。定期执行 `git fetch --prune` 清理远程已删除分支的本地记录。

示例

示例

Input

git stash

Output

Stash working changes

FAQ

包含高级命令吗?

聚焦日常操作; rebase -i、filter-branch 等见官方文档。

需要联网吗?

不需要,纯静态参考页。

为什么我克隆的仓库没有.git目录?

可能使用了 `--depth=1` 浅克隆参数,这只会下载最新版本历史以节省空间。要获取完整历史,重新克隆时不加该参数,或对现有仓库执行 `git fetch --unshallow` 补全历史。