阅界食谱今天吃什么,先来这里看看
代码片段

Git 常用命令(日常 12 条)

提交、回退、查看历史最常用的 Git 命令。

模板正文

# 状态与提交
git status                     # 看当前改动
git add -p                     # 逐块挑选要提交的改动(推荐)
git commit -m "fix: 修复登录超时"

# 历史与差异
git log --oneline --graph -20  # 看最近 20 条提交
git diff --staged              # 看已暂存的内容
git show <commit>              # 看某次提交改了什么

# 撤销
git restore <file>             # 丢弃工作区改动
git restore --staged <file>    # 取消暂存(保留改动)
git reset --soft HEAD~1        # 撤销上一次提交,改动保留

# 分支
git switch -c feat/xxx         # 新建并切换分支
git switch main                # 切回主分支
git fetch --prune              # 拉取并清理已删除的远程分支

怎么用

贴在备忘录里,前两周基本天天用得到。

使用要点

  • 提交前先 git diff --staged 看一遍,能避免提交调试代码。
  • 已经 push 的提交不要用 reset 改写,用 revert 更安全。

同类模板

Git 常用命令(日常 12 条) · 阅界食谱