您可以使用
git status --porcelain
命令一次性获取工作目录和暂存区的完整状态。
$ git status --porcelain
A that
MM this
?? blah
第一列是暂存区的状态,第二列是工作目录的状态。上面的内容表示
that
已被添加到暂存区,
this
有已暂存和未暂存的修改,
blah
未被跟踪。
以下是同样的内容,但是更详细。
$ git status
On branch feature
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: that
modified: this
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: this
Untracked files:
(use "git add <file>..." to include in what will be committed)
blah
但我猜想你真正想要的是在提交之前查看即将更改的内容。在这种情况下,我建议你不要这样做。相反...
- 不使用
-m
。
- 使用
-v
。
- 用
git commit --amend
来修复任何错误。
git commit -m
是一个坏习惯。这意味着你的提交信息将只有一行,缺乏细节。一个好的提交信息应该是:
简要总结。
详细信息,详细信息。
git commit -m
会阻碍这一点,而那些细节在以后将非常重要,你永远无法再次获得它们。值得额外几秒钟的时间。
更重要的是,常规的git commit
会拉起编辑器,并显示即将提交的内容。
更好的是,如果您使用git commit -v
,您将获得完整的差异以进行审查。我经常使用此功能,我已将其别名设置为git ci
(检入)。
diff --git a/that b/that
new file mode 100644
index 0000000..e69de29
diff --git a/this b/this
index 73e4f83..f129e32 100644
--- a/this
+++ b/this
@@ -4,3 +4,5 @@ fix
1
2
3
+4
+
最后,与其他版本控制系统不同,Git中的提交不会立即共享。除非你使用git push
。这意味着如果你在提交时犯了一个错误,你可以快速修复它。只需进行修复并使用git commit --amend
,上一个提交将被更新。
所以,与其添加许多层来防止自己犯错,不如直接修复错误。这就是版本控制的美妙之处!
git commit -m "Message" file1.txt file2.txt
- 1615903