提交 History 练习
你将构建什么
仓库使用 at 最少 three 提交, 每个添加 or 更改 file. 你将 读取 log and 验证那个 history tells 清晰 story 的什么 happened.
学习目标
- 制作多个 sequential 提交使用 meaningful 消息
- Use git log --oneline for compact history view
- See 如何每个提交 captures distinct snapshot
- 练习编写提交消息那个描述更改
前置要求
- git init, 添加, and 提交 (创建仓库 Workflow 项目)
步骤
- 1
设置仓库
创建新 仓库 and 制作初始提交使用 README. 这个是 开始点 你将 构建 history on 顶部的.
代码mkdir history-exercise cd history-exercise git init echo "# History Exercise" > README.md git add . git commit -m "Initial commit with README"预期结果
仓库使用 one 提交 in 它的 history.
- 2
添加其次 file and 提交
创建新 file, stage 它, and 提交使用消息那个描述什么是 添加. 好消息 say 什么 and 为什么, 不只是 "update".
代码echo "print('hello')" > hello.py git add hello.py git commit -m "Add hello.py greeting script"预期结果
其次提交是 添加到 history.
提示
消息 "Add hello.py greeting script" 是远 更多 useful than "add file".
- 3
修改 existing file and 提交
Append 行到 README.md, stage 它, and 提交. 修改 existing file 是只是 as 常见 as 添加新 ones — workflow 是 identical.
代码echo "" >> README.md echo "## Files" >> README.md echo "- hello.py: prints a greeting" >> README.md git add README.md git commit -m "Document hello.py in README"预期结果
第三提交记录 README 更新.
- 4
读取 history
运行 git log --oneline for compact one-行-每-提交 view. 然后运行 git log 到 see 完整消息, authors, and timestamps. 读取 history 是如何你 理解项目's story.
代码git log --oneline git log预期结果
Three 提交 listed, 大多数 recent 首先, 每个使用清晰消息.
- 5
验证仓库状态
使用 git status 和 git log 确认当前仓库状态干净、提交历史符合预期。在执行任何破坏性操作前,先看清当前状态是 Git 的最佳实践。
代码git status # Should show: nothing to commit, working tree clean git log --oneline -5 # Review the last 5 commits to confirm history git branch -v # List branches with last commit info预期结果
git status 显示工作树干净;git log 显示预期的提交历史。
自己动手试试
# TODO: create repo, make 3 commits with clear messages, then read the log
mkdir history-exercise
cd history-exercise
git initmkdir history-exercise
cd history-exercise
git init
echo "# History Exercise" > README.md
git add .
git commit -m "Initial commit with README"
echo "print('hello')" > hello.py
git add hello.py
git commit -m "Add hello.py greeting script"
echo "" >> README.md
echo "## Files" >> README.md
echo "- hello.py: prints a greeting" >> README.md
git add README.md
git commit -m "Document hello.py in README"
git log --oneline
git log你学到了什么
你构建 three-提交 history 使用 descriptive 消息 and 读取它 后面使用 git log — 相同 skill 你 use 每个 day 到理解什么更改 in 任何项目 and 为什么.
相关资源
相关练习
- Git Commands MCQ
测验 on git 添加, 提交, and log behavior.
- 提交消息 MCQ
Identify 好对比. 坏提交消息.
相关工具
- Code Diff
Compare 更改之间提交到 see 什么每个提交做.
- .gitignore Generator
添加 .gitignore 到 keep junk files out 的 history.
相关速查表
- Git Cheatsheet
引用 for log flags and 提交消息约定.
相关参考文档
- Git Commands 引用
引用 for git log flags and 提交消息约定.
相关错误
- 合并 Conflict
Resolving conflicting 更改.
- Uncommitted 更改
工作使用 uncommitted 更改.
相关术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
相关错误
用大白话解释常见错误——什么意思、为什么发生、如何修复。
- 合并 Conflict
Resolving conflicting 更改.
- Uncommitted 更改
工作使用 uncommitted 更改.