git - Undo local changes interactive -


i add debug code while developing need remove these changes later.

currently, check git diff , remove changes manually or type git checkout -- myfilename if undo entire file.

i love interactive patch function (git add -i). there tool or command in git can undo changes interactive git add -i?

in other words: interactively checkout files , hunks out of index.

what looking think git reset --patch or git reset -p

from the docs:

git reset (--patch | -p) [] [--] [...]

interactively select hunks in difference between index , (defaults head). chosen hunks applied in reverse index.

this means git reset -p opposite of git add -p, i.e. can use selectively reset hunks. see “interactive mode” section of git-add(1) learn how operate --patch mode.

and git add -p it says

-p

interactively choose hunks of patch between index , work tree , add them index. gives user chance review difference before adding modified contents index.

this runs add --interactive, bypasses initial command menu , directly jumps patch subcommand. see “interactive mode” details.

so git reset -p can select reset.


edit:

as git checkout manual page mentions:

-p

--patch

interactively select hunks in difference between (or index, if unspecified) , working tree. chosen hunks applied in reverse working tree (and if specified, index).

this means can use git checkout -p selectively discard edits current working tree. see “interactive mode” section of git-add(1) learn how operate --patch mode.

so command looking is

$git checkout -p 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -