git查看状态和修改信息

本文介绍了如何使用git工具检查文件状态和查看修改内容。通过`git status`和`git diff`命令,我们可以了解文件的修改情况,并使用`git add`和`git commit`进行提交操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

之前的文章(git创建版本库)已经添加并提交了一个readme.txt文件

  • 现在我们继续工作,修改一下readme.txt文件内容
  • 然后运行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 status 命令可以让我们时刻掌握仓库当前的状态,上面的命令输出告诉我们,readme.txt被修改过了,但还没有准备提交的修改

  • git diff查看修改的内容
lvjingying@LAPTOP-VGTK7EP5 MINGW64 /e/githome/learngit (master)
$ git diff
diff --git a/readme.txt b/readme.txt
index 7abd34b..3ba3ac2 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,2 +1,2 @@
 Git is one
-Git is two
\ No newline at end of file
+Git is two  改动
\ No newline at end of file

从上面的输出可以看到,我们在第二行添加了“改动”汉字

  • 知道了有什么改动之后。提交就放心多了。git add
lvjingying@LAPTOP-VGTK7EP5 MINGW64 /e/githome/learngit (master)
$ git add readme.txt
  • 在git commit之前我们在看看状态
lvjingying@LAPTOP-VGTK7EP5 MINGW64 /e/githome/learngit (master)
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   readme.txt

git status告诉我们,将要被提交的修改包括readme.txt下面可以放心的提交了

lvjingying@LAPTOP-VGTK7EP5 MINGW64 /e/githome/learngit (master)
$ git commit -m "修改了第二行加了中文改动"
[master 376ad95] 修改了第二行加了中文改动
 1 file changed, 1 insertion(+), 1 deletion(-)
  • 再看看仓库状态

lvjingying@LAPTOP-VGTK7EP5 MINGW64 /e/githome/learngit (master)
$ git status
On branch master
nothing to commit, working tree clean

Git告诉我们当前没有需要提交的修改

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值