回顾与练习
关键要点
- 就是项目的存档点——一条你随时可以跳回去的完整时间线,正是它让你能够毫无顾虑地放手让 AI 去干。
- 核心节奏是
add→commit→push:暂存你的改动,用一条清晰的消息把它存为一次 commit,再推送到 GitHub 以备份和分享。 - 任何大动作之前先开分支,每次提交之前先读 diff——这是你抓住 AI 删掉不该删的东西的方法。
.gitignore把机密(如.env)和垃圾(如node_modules/)挡在历史之外。提交到 GitHub 的机密即便事后删除,也视为永久泄露。- 你可以让 AI 来运行命令,但理解每条命令做了什么的责任仍在你身上——尤其是
reset --hard这类破坏性命令。
动手试试
新建一个全新的文件夹,亲手把整个流程跑一遍:git init,创建一个包含 .env 的 .gitignore,添加一个简单的 notes.txt 文件,然后 git add . 和 git commit -m "Initial commit"。现在运行 git log --oneline 看看你的存档点,编辑这个文件,再运行 git diff,看 Git 把改了什么精确地展示给你。你刚刚在一个绝不会出错的项目上,用过了本章所有的核心习惯。
本章提示词
I'm learning Git as a beginner and I want you to run the commands for me,
but teach as you go. For the task below:
<describe what you want to do — e.g. "save my current work" or "try a risky change safely">
- Tell me which Git commands you'll run and what each one does in plain English.
- If anything is destructive (reset --hard, force-push, deleting a branch),
warn me clearly and explain what I'd lose before doing it.
- Before any commit, show me the diff and summarize what changed.
- Remind me if there's anything in the change that shouldn't be public (secrets, keys).