The problem is that I cannot apparently make a partial commit of four lines' worth of changes in a file, out of about all 200 or so changed lines in that file. It might be due to the command I mistakenly did and then supposedly corrected. I am an experienced git user and I have done this sort of task before, but I always did it without making a mistake previously.
Here is what I did.
I have a file with 3 or 4 changes to it, including one that I think might be desirable even if the other changes are too experimental.
I also have some renamed files, so the renames are staged.
I did the usual git add -p file
step and verified that git diff --cached file
showed exactly the change I wanted to check in.
I accidentally did git commit -m "Message"
(omitting the file name I should have included) and it committed the (staged) renames, which was not desired, as well as file
.
Then I backed that commit out with git reset HEAD~1 --soft
. This canceled the commit, but left file
in a staged state, with ALL the changes, not just the add -p
changes, as shown by git diff --cached file
.
Because I didn't want all the changes staged for commit yet, I reset the file with git reset HEAD file
. At this point git status
and git diff
seem to show that I am back to the state I was in before the git add -p file
command.
The problem is that, at this point, if I do the following with only the desired change accepted during the add,
git add -p file
git commit file -m "Message"
The status shows all the changes to file
getting committed. The line counts show way too many lines after the commit is completed.
I how do I only commit what I chose during git add -p file
now that it seems like I am blocked from doing so?
Commentary: Ordinarily I don't have staged renames, so ordinarily I don't have to try to specify the file I want to commit. I think that the meaning of git commit file
is not the meaning I need for my purpose. From reading the man page, I think what it's trying to say is that it doesn't matter what is staged for file
when you do git commit file
, it will commit that file's complete set of changes. Also git commit -p file
will do the right thing for file
after letting me pick the change interactively, but it will also commit the unrelated renamings that are staged.