I ran git add
on some files, constituting a logical separate set of changes, made other changes to them and extracted another logical set of changes using git add -p
. Half way through, I realize that I have not committed the previous set, yet.
The interactive help of git add -p
only gives the following options:
Stage this hunk [y,n,q,a,d,/,s,e,?]? ?
y - stage this hunk
n - do not stage this hunk
q - quit; do not stage this hunk nor any of the remaining ones
a - stage this hunk and all later hunks in the file
d - do not stage this hunk nor any of the later hunks in the file
g - select a hunk to go to
/ - search for a hunk matching the given regex
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk
k - leave this hunk undecided, see previous undecided hunk
K - leave this hunk undecided, see previous hunk
s - split the current hunk into smaller hunks
e - manually edit the current hunk
? - print help
How can I reset the added patches?
git add -p
stages changes without storing a history, which could be used to revert the addition. You can however usegit reset -p
orgit reset --patch
to unstage the changes. A procedure would look something line the following:q
to exit the interactive
git add -p
git reset -p
to reset all changes that were added by mistake
git commit
to commit the first changeset
git add -p
again, adding changes to a new second commit
git commit
to commit the second commit