Question

I have a file that I've been working on and then realized that I had a mistake in it a few lines above where I've been working. I quickly fixed the mistake and want to commit it before I commit the rest of my work. Great, this is where git add --patch comes in!

Except, I'm being presented with only one hunk incorporating both changes. Is it possible to manually tell git that I want two hunks?

Was it helpful?

Solution

In addition to 'y' and 'n', one of the answers you can give when it asks you about a hunk is 's', for 'split this hunk in to smaller hunks'. The full list:

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 and all the remaining hunks in the file
d - do not stage this hunk nor any of the remaining 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

OTHER TIPS

git gui will allow you to commit single lines, even if they are surrounded by other modified lines you do not want to commit.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top