Skip to content

创建仓库 Workflow

入门 约 10 分钟

你将构建什么

局部 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. 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. 2

    创建 README file

    创建 README.md 使用 title 行. README 是前面 page 的仓库 — 每个项目应该有 one.

    代码
    echo "# My First Repo" > README.md

    预期结果

    file README.md exists in folder 使用 one 行的 内容.

  3. 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".

  4. 4

    制作你的首先提交

    运行 git 提交使用消息. 消息描述什么这个 snapshot 包含. 检查 log 到 see 你的提交 recorded in history.

    代码
    git commit -m "Add README"
    git log

    预期结果

    git log shows one 提交使用你的消息, author, and timestamp.

  5. 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 显示预期的提交历史。

自己动手试试

你学到了什么

你练习完整首先-仓库 workflow: init, 添加, 提交, 状态, log. 这些 five commands 是基础的 每个 Git 会话.

相关资源

相关课程

  • Git 基础

    init, 添加, 提交, 状态, and log commands used 这里.

相关练习

相关工具

相关速查表

相关参考文档

相关错误

相关术语

相关术语

新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。

相关错误

用大白话解释常见错误——什么意思、为什么发生、如何修复。

← 返回主题