查看当前状态

GitGitBeginner
立即练习

This tutorial is from open-source community. Access the source code

💡 本教程由 AI 辅助翻译自英文原版。如需查看原文,您可以 切换至英文原版

简介

Git 是一个广受欢迎的版本控制系统,它允许开发者追踪其代码库中的更改。Git 最重要的特性之一就是能够查看工作目录的当前状态。在本实验中,你将学习如何使用 git status 命令来查看你的 Git 仓库的当前状态。


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL git(("`Git`")) -.-> git/BasicOperationsGroup(["`Basic Operations`"]) git/BasicOperationsGroup -.-> git/status("`Check Status`") subgraph Lab Skills git/status -.-> lab-12781{{"`查看当前状态`"}} end

查看当前状态

作为一名开发者,了解你的 Git 仓库的当前状态非常重要。这包括哪些文件被修改了、哪些文件已暂存待提交以及哪些文件未被跟踪等信息。git status 命令以易于阅读的格式提供这些信息。

你的任务是使用 git status 命令查看位于 https://github.com/labex-labs/git-playground 的 Git 仓库的当前状态。你应该留意命令的输出并尝试理解其含义。

要完成本实验,你需要克隆位于 https://github.com/labex-labs/git-playground 的 Git 仓库。

  1. 克隆仓库后,导航到仓库的根目录:
cd git-playground
  1. 查看 Git 仓库的当前状态:
git status

这将输出工作目录的当前状态。你应该会看到你当前所在的分支、你的分支是否与远程仓库同步,以及任何未跟踪或已修改的文件的相关信息。

输出如下所示:

On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")

总结

在本实验中,你学习了如何使用 git status 命令来查看 Git 仓库的当前状态。现在你应该能够理解该命令的输出,并使用它来跟踪代码库中的更改。记得经常使用 git status 以随时了解你的 Git 仓库的状态。

您可能感兴趣的其他 Git 教程