Git与Github使用之--常用本地命令介绍

本文介绍了如何使用git status命令查看仓库状态,包括工作区是否干净、哪些文件被修改等信息;同时,还介绍了如何使用git diff命令查看具体修改内容,帮助开发者更好地管理版本。

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

查看当前仓库状态

运行git status 命令可以查看结果:

MacBook-Pro-2% git status
On branch master
nothing to commit, working tree clean

git status 可以让我们时刻掌握仓库当前状态,上面的命令告诉我们在上次提交后没有被修改的文件
,那么我们修改后再试试看:

MacBook-Pro-2% 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")
MacBook-Pro-2% 

这里没有显示修改的内容,如果能看什么被修改了但是没提交那是极好的。所以我们需要git diff 这个命令来看看:

MacBook-Pro-2% git diff
diff --git a/readme.txt b/readme.txt
index 884b2bc..0b138d6 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,2 +1,3 @@
 this is the readme file for myweb
 i can learn web by practice!
+we can show our reaserch result though web tech!

我们在这里可以看到readme.txt文件被修改了,并且知道了修改了什么内容,接下来就可以先用git add 再用git commit 来提交修改了:

MacBook-Pro-2% git add readme.txt
MacBook-Pro-2% git commit -a
Aborting commit due to empty commit message.
MacBook-Pro-2% git commit -m "add distributed"
[master 130362a] add distributed
 Committer: Chenjun Xiong <ChadwinSean@MacBook-Pro-2.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:

    git config --global --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 1 insertion(+)
MacBook-Pro-2% git status
On branch master
nothing to commit, working tree clean
MacBook-Pro-2% 

这次我们学习了git statusgit diff的使用。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值