首页 > 编程笔记

git status命令:查看仓库的状态

git status 命令用于显示 Git 仓库的状态。这是一个十分常用的命令,请务必牢记。

工作树和仓库在被操作的过程中,状态会不断发生变化。在 Git 操作过程中时常用 git status 命令查看当前状态,可谓基本中的基本。

下面,就让我们来实际查看一下当前状态。

$ git status
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)

结果显示了我们当前正处于 master 分支下,接着还显示了没有可提交的内容。

所谓提交(Commit),是指“记录工作树中所有文件的当前状态”。

尚没有可提交的内容,就是说当前我们建立的这个仓库中还没有记录任何文件的任何状态。这里,我们建立 README.md 文件作为管理对象,为第一次提交做前期准备。

$ touch README.md
$ git status
# On branch master
#
# Initial commit
## Untracked files:#  (use "git add <file>……" to include in what will be committed)#
# README.md
nothing added to commit but untracked files present (use "git add" to track)

可以看到在 Untracked files 中显示了 README.md 文件。类似地,只要对 Git 的工作树或仓库进行操作,git status 命令的显示结果就会发生变化。

推荐阅读