I used git add -p to split my code changes into multiple commits. However, doing git commit after that commits all changes, including the unstaged ones. I looked at a few questions on SO, but could not find any obvious mistake. Could you please help me understand what I am doing wrong? Below are the commands I tried, and their outputs.
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
Don’t specify the filename in the
git commitcommand.By default,
git commitwith no other parameters commits the contents of the index (whatever you have staged viagit add).If you specify a filename, however, (e.g.
git commit <filename>), then Git actually bypasses the index entirely and commits the current state of the specified file(s) as they are in the working directory.Basically, either use
git addor specify filenames withgit commit, but don’t do both.