Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

git add - Why is split option missing in git add -p?

Trying to split a hunk into smaller ones by git add -p and split option, but entire file appears as one hunk and I can't split it.

  1. I can edit, but removing lines causes the patch to fail.
  2. git help add says I should have split, and I recall using it, but in my current example the option doesn't appear in the prompt.
  3. When I choose the option help is printed, which says I can choose s to split :-[

Git version: 1.9.1. Xubuntu 14, oh-my-zsh. The hunk is not one line, it's multiple lines. Any ideas why would that be?

Edited with more data, here's console log:

+last line of long text 
Stage this hunk [y,n,q,a,d,/,e,?]? s
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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The reason it's not working is because your hunk is already as small as git will automatically get it. Split only works when there are non-changed lines separating changed lines close enough that git assumes they belong together.

In order to achieve what you want, you will need to manually edit the patch


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...