I have just applied a patch to 3 files, their diff can be seen here:
The task is to separate the patch into various commits, like comments, license, refactoring etc.
For that I will use git add -p:
First hunk is license of
main.c, trivial, i pressy.Second hunk is in
stack.cand contains one hunk of license followed by two hunks of comments. Isplit and thenynnI will keep doing this for the rest of
git add -p.
HOWEVER, it looks like none of the n applied!
To confirm my suspicions I will do a fresh git add -p again, this time I will use e and this will become this.
git then outputs fatal: corrupt patch at line 50. So basically my s and n tried to not stage certain hunks but ended up discarding those removals.
+ lines should be removed without problems unlike - (where you have to replace that line with space), right? What am I doing wrong?
Looks like you did not follow
git add -p+git commitat each step. Saying "no" withnmeans that the remaining changes haven't been staged. You need to repeatgit add -pfollowed bygit commitfor each type of change that you want to appear in each commit.This is by design. It means you did not want that in the index. So the changes were not staged. When you commit, they will not be part of that commit. You must repeat the process to get /those/ in like the previous iteration.
You are done with
git add -p+git commititerations once there are no more outstanding changes to commit.Again, the hunks you say "no" to with
nwill NOT be part of the commit you make withgit commit.It may be that you need to read up on how git's staging (or index) works.