status命令的使用
2.1 status命令的使用
如果需要查看工作区的状态,比如是否有文件需要提交等等,可以使用status命令。
readme.txt 文件内容默认如下:
Git is a version control system.
Git is free software.
修改readme.txt文件中的内容如下:
Git is a distributed version control system.
Git is free software.
使用git status 命令,输出如下:
# git status
# On branch master
# 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 diff 命令查看内容变化:
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. 可以看出 +开头的这一句是被修改后的内容。
使用 add 命令 添加提交:
git add readme.txt
再次使用status 查看 发现提示已经发生变化。
# git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: readme.txt
#
最后使用 commit 提交更改
git commit -m "add distributed"
[master dae675a] add distributed
1 file changed, 1 insertion(+), 1 deletion(-)
再次使用status 查看工作区状态,没有任务需要提交并且工作区是干净的[提交已经成功完成]
git status
# On branch master
nothing to commit (working directory clean)
总结:
使用 status 命令可以随时查看工作区状态。如果有任何需要提交的文件 将会收到提示。
本文详细介绍了如何使用Git中的status命令来检查工作区的状态,包括如何查看未提交的更改、使用add命令准备提交以及最终提交更改的过程。

1823

被折叠的 条评论
为什么被折叠?



