git 状态查看

git status

git status 命令可以让我们时刻掌握仓库当前的状态,比如我们修改了一个名叫 readme.txt 的文件,使用 git status 可以看到已修改状态:

$ git status
On branch future
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
        modified:   readme.txt
no changes added to commit (use "git add" and/or "git commit -a")
$ git add readme.txt
$ git status
On branch future
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)
        modified:   readme.txt
$ git commit -m readme.txt
$ git status
On branch future
nothing to commit, working tree clean
  • Untracked files 未跟踪的文件
  • Changes not staged for commit 已跟踪文件内容的变化,未暂存
  • Changes to be committed 已暂存, 未提交

  • no changes added to commit 修改未暂存
  • Changes to be committed 修改已暂存未提交
  • nothing to commit, working tree clean 没有任何修改, 工作空间很"干净"

状态简览

使用 git status -sgit status --short 以简短的形式输出文件状态

$ git status -s
 M README
MM Rakefile
A  lib/git.rb
M  lib/simplegit.rb
?? LICENSE.txt
  • ?? 新添加的未跟踪文件
  • A 新添加到暂存区中的文件
  • 右边的M 修改了但是还没放入暂存区
  • 左边的M 修改了并放入了暂存区
  • MM 在工作区被修改并提交到暂存区后又在工作区中被修改了,所以在暂存区和工作区都有该文件被修改了的记录

git diff

git diff 顾名思义就是查看 difference,显示的格式正是 Unix 通用的 diff 格式,可以从上面的命令输出看到,我们在第一行添加了一个“distributed”单词。

$ git diff readme.txt
diff --git a/readme.txt b/readme.txt
index 46d49bf..9247db6 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,2 +1,2 @@
-Git is a version control system.
+Git is a distributed version control system.
 Git is free software.

MIT Licensed | Copyright © 2018-present 滇ICP备16006294号

Design by Quanzaiyu | Power by VuePress