Can I modify git-add's hunk size?

2019-02-07 19:09发布

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?

标签: git patch add
2条回答
家丑人穷心不美
2楼-- · 2019-02-07 19:43

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

查看更多
女痞
3楼-- · 2019-02-07 19:49

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
查看更多
登录 后发表回答