The reason I am asking this is that I had accidentally done a git commit -a
that included a file I did not yet want to commit. My solution was to do the following:
git reset --soft HEAD^
git reset -- file/with/changes_not_to_committed
git commit -C HEAD@{1}
Here, I’ve rewound the branch by one commit while keeping the index and working tree, then pulled file/with/changes_not_to_committed
from a yet older revision into the index, and then I committed the index using the commit message from the previous branch head commit. Neither git-reset
invocation touches the working copy, so my modifications to file/with/changes_not_to_committed
persist, but are no longer recorded in the HEAD
revision.
However, it would have been easier if I could pull file/with/changes_not_to_committed
from the HEAD^
revision right into the index without touching the working copy. Since the index otherwise already represents the state I want, I could then just amend the HEAD
commit, producing a sequence like this:
git magic-pony HEAD^ file/with/changes_not_to_committed
git commit --amend -C HEAD
This is almost what I would get by replacing git-magic-pony
with git-checkout
, except for the requirement that the working copy be left untouched and only the index updated. It seems there is no way to make git-checkout
not touch both.
My question is: does git-magic-pony
exist, and if so, under what name?