1. git status 的补充

1.1 status 有个参数 -s

[Git] 008 status 与 commit 命令的补充 随笔 第1张


SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

1.2 git status -s 显示的信息比 git status 简洁

[Git] 008 status 与 commit 命令的补充 随笔 第2张


1.3 不妨再添加一个文件

[Git] 008 status 与 commit 命令的补充 随笔 第3张


1.4 往 note_01.txt 中写入文本

[Git] 008 status 与 commit 命令的补充 随笔 第4张


1.5 用 git status -s 查看

[Git] 008 status 与 commit 命令的补充 随笔 第5张

  • note_01.txt 前有红色的 ??,说明 note_01.txt 还没有进行过 addcommit 操作

1.6 将 note_01.txt 加入暂存区后再查看

[Git] 008 status 与 commit 命令的补充 随笔 第6张

  • note_01.txt 前有绿色的 A,说明 note_01.txt 已经被加到暂存区了

1.7 继续往 note_01.txt 中添加文本

[Git] 008 status 与 commit 命令的补充 随笔 第7张


1.8 再查看一下

[Git] 008 status 与 commit 命令的补充 随笔 第8张

  • note_01.txt 前有绿色的 A 与 红色的 M
  • 绿色的 A 说明 note_01.txt 已经被加到暂存区了
  • 红色的 M 说明工作区的 note_01.txt 做了修改,与暂存区的 note_01.txt 不同了

2. git commit 的补充

2.1 commit 有个参数 -m

  • git commit -m 后面要跟一句解释说明

[Git] 008 status 与 commit 命令的补充 随笔 第9张


2.2 再查看一下

[Git] 008 status 与 commit 命令的补充 随笔 第10张

  • 此时加入仓库的是暂存区的 note_01.txt

2.3 既然工作区的 note_01.txt 有了变动,那就再提交给仓库

  • 提交过一次的文件,可以使用 git commit -am 命令
  • -am 相当于结合了 add-m

[Git] 008 status 与 commit 命令的补充 随笔 第11张


2.4 漏了一句话怎么办?

方法一:加上那句话,再提交一次(略)

方法二:使用 git commit --amend

  • 其实这里犯了个错误,坑就不挖了,见 [Git] 009 逆转未来

  • 此法可以把两次提交当作一次,但纪录中仍有两条

[Git] 008 status 与 commit 命令的补充 随笔 第12张


[Git] 008 status 与 commit 命令的补充 随笔 第13张


[Git] 008 status 与 commit 命令的补充 随笔 第14张


方法三:方法二的进阶版,git commit --amend --no-edit

  • 其实这里犯了个错误,坑就不挖了,见 [Git] 009 逆转未来
  • 此法也可混入上一个提交队列,并且可以不写“注释”,但记录仍然存在

[Git] 008 status 与 commit 命令的补充 随笔 第15张


2.5 有参数可以在第一次 commit 时不写“注释”

  • 挖个坑,日后填平
  • 坑号编码:Git08-1
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄