开发工具
Git 备忘单
常用 Git 命令备忘单,支持搜索和复制
基础
初始化仓库
init
在当前目录初始化一个 Git 仓库
git init
克隆仓库
clone
从远端克隆
git clone <repo-url>
查看状态
status
查看工作区和暂存区状态
git status
提交
添加文件到暂存区
add
添加单个或全部文件
git add <file>|git add .
提交
commit
提交已暂存的变更
git commit -m "描述"
修改上次提交
amend
修改最近的一次提交(非公共分支慎用)
git commit --amend
分支
创建/切换分支
branch
创建并切换到新分支
git checkout -b <branch>
切换分支(新)
switch
使用 switch 切换分支
git switch <branch>
合并分支
merge
把 feature 合并到 main
git merge <branch>
变基
rebase
交互式变基以整理提交
git rebase -i <base>
摘樱桃
cherry-pick
把指定提交应用到当前分支
git cherry-pick <commit>
杂项
保存当前修改
stash
临时保存未提交的修改
git stash|git stash pop
回退
回退(保留修改)
reset-soft
回退 commit,但保留工作区修改
git reset --soft <commit>
强制回退
reset-hard
彻底回退到指定提交(危险)
git reset --hard <commit>
恢复
恢复误删提交
reflog
查看引用日志并恢复
git reflog
远程
添加远端
remote-add
添加远端仓库并命名
git remote add origin <repo-url>
推送
push
推送到远端分支
git push origin <branch>
拉取并合并
pull
从远端拉取并合并
git pull
抓取远端
fetch
只抓取远端更新不合并
git fetch
查看
查看提交日志
log
简洁日志格式
git log --oneline --graph --decorate
配置
配置用户名/邮箱
config
设置仓库或全局用户名和邮箱
git config --global user.name "Name" git config --global user.email "you@example.com"