# ===== CodeLab: git-undo =====
# 以下代码片段按文章出现顺序拼接, 共 8 段

# ----- 片段 1 (bash) -----
git restore main.py
# 旧版写法:git checkout -- main.py

# ----- 片段 2 (bash) -----
git restore --staged main.py
# 旧版写法:git reset HEAD main.py

# ----- 片段 3 (bash) -----
git add 漏掉的文件.py
git commit --amend -m "修正后的提交信息"

# ----- 片段 4 (bash) -----
git reset --soft HEAD~1    # 撤销提交,改动留在暂存区
git reset --mixed HEAD~1   # 撤销提交,改动回到工作区(默认)
git reset --hard HEAD~1    # 撤销提交,改动全部丢弃

# ----- 片段 5 (bash) -----
git merge --abort   # 放弃本次合并,回到合并前
git rebase --abort  # 放弃本次变基,回到变基前

# ----- 片段 6 (bash) -----
git revert 提交哈希
git push

# ----- 片段 7 (bash) -----
git reflog
# 输出类似:
# a1b2c3d HEAD@{0}: reset: moving to HEAD~1
# f9e8d7c HEAD@{1}: commit: 完成登录功能

# ----- 片段 8 (bash) -----
git reset --hard f9e8d7c
