git commit提交unstaged hunks

Mas*_*Man 2 git

我曾经git add -p将我的代码更改拆分为多个提交.但是,在此git commit之后执行所有更改,包括未分阶段的更改.我看了几个关于SO的问题,但没有发现任何明显的错误.你能帮我理解我做错了什么吗?以下是我尝试的命令及其输出.

bash-3.2$ git diff test11.txt
diff --git a/test11.txt b/test11.txt
index f077274..e811cae 100644
--- a/test11.txt
+++ b/test11.txt
@@ -1,5 +1,5 @@
-Hello
-World
+hello
+world

-Blahblahblah
-blah
+blahblahblah
+Blah
bash-3.2$ git add -p test11.txt
diff --git a/test11.txt b/test11.txt
index f077274..e811cae 100644
--- a/test11.txt
+++ b/test11.txt
@@ -1,5 +1,5 @@
-Hello
-World
+hello
+world

-Blahblahblah
-blah
+blahblahblah
+Blah
Stage this hunk [y,n,q,a,d,/,s,e,?]? s
Split into 2 hunks.
@@ -1,3 +1,3 @@
-Hello
-World
+hello
+world

Stage this hunk [y,n,q,a,d,/,j,J,g,e,?]? y
@@ -3,3 +3,3 @@

-Blahblahblah
-blah
+blahblahblah
+Blah
Stage this hunk [y,n,q,a,d,/,K,g,e,?]? n

bash-3.2$ git status
# On branch test
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   test11.txt
#
# 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:   test11.txt
bash-3.2$ git commit test11.txt
[test 1b85189] Test12
 1 files changed, 4 insertions(+), 4 deletions(-)
bash-3.2$ git status
# On branch test
nothing added to commit
Run Code Online (Sandbox Code Playgroud)

Amb*_*ber 10

不要在git commit命令中指定文件名.

默认情况下,git commit没有其他参数提交索引的内容(无论你通过哪个阶段git add).

如果您指定的文件名,然而,(例如git commit <filename>),那么实际的Git完全绕过该指数并提交指定的文件(S),因为他们是在工作目录的当前状态.


基本上,使用git add 指定文件名git commit,但不要同时使用指定文件名.