创建仓库 Workflow
你将构建什么
局部 Git 仓库使用 README.md file and one 提交. 你将 运行每个 command 你自己 and 读取输出 at 每个步骤.
学习目标
- Initialize 新仓库使用 git init
- 创建 and stage file 使用 git 添加
- 记录 snapshot 使用 git 提交
- Inspect 仓库状态使用 git 状态 and git log
前置要求
- Git 安装 and available on command 行
- terminal or CoderNewbie playground shell
步骤
- 1
创建项目 folder and init
创建新 空 directory and 运行 git init 内部它. 这个 turns folder 到 Git 仓库通过创建隐藏 .git directory 那个存储所有 history.
代码mkdir my-first-repo cd my-first-repo git init预期结果
Git prints "Initialized empty Git repository in .../my-first-repo/.git/".
- 2
创建 README file
创建 README.md 使用 title 行. README 是前面 page 的仓库 — 每个项目应该有 one.
代码echo "# My First Repo" > README.md预期结果
file README.md exists in folder 使用 one 行的 内容.
- 3
Stage and 检查状态
运行 git 添加到 stage file, 然后 git 状态到 see 什么将 是 committed. Staging 是步骤之间你的工作 files and committed snapshot.
代码git add README.md git status预期结果
git 状态 shows README.md in green under "Changes to be committed".
提示
Use git 添加 . 到 stage 所有更改 at 一次, 但是 careful — 它 stages 一切.
- 4
制作你的首先提交
运行 git 提交使用消息. 消息描述什么这个 snapshot 包含. 检查 log 到 see 你的提交 recorded in history.
代码git commit -m "Add README" git log预期结果
git log shows one 提交使用你的消息, author, and timestamp.
- 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 显示预期的提交历史。
自己动手试试
# Run these commands in a terminal, one at a time
mkdir my-first-repo
cd my-first-repo
git init
# TODO: create README, add, commit, logmkdir my-first-repo
cd my-first-repo
git init
echo "# My First Repo" > README.md
git add README.md
git status
git commit -m "Add README"
git log你学到了什么
你练习完整首先-仓库 workflow: init, 添加, 提交, 状态, log. 这些 five commands 是基础的 每个 Git 会话.
相关资源
相关课程
- Git 基础
init, 添加, 提交, 状态, and log commands used 这里.
相关练习
- Git Commands MCQ
测验 on 什么每个基础 Git command 做.
- Git Workflow Predict
Predict 状态的 仓库之后序列的 commands.
相关工具
- .gitignore Generator
Generate .gitignore file for 你的新 仓库.
- Markdown Previewer
Preview 你的 README.md rendered as HTML.
相关速查表
- Git Cheatsheet
快速引用 for 每个 command used 在本项目中.
相关参考文档
- Git Commands 引用
完整引用 for init, 添加, 提交, 状态, and log.
相关错误
- 不 Git 仓库
常见 git init mistakes.
- Uncommitted 更改
工作使用 uncommitted 更改.
相关术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
相关错误
用大白话解释常见错误——什么意思、为什么发生、如何修复。
- 不 Git 仓库
常见 git init mistakes.
- Uncommitted 更改
工作使用 uncommitted 更改.