Re: How to split a big commit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Nguyen,

Nguyen Thai Ngoc Duy writes:
> After a lot of small commits and a few mixed up large commits, it was
> too messy that I merged them all into one big commit then started
> spliting it into smaller, reasonable patches. Just wonder if anybody
> else faces the same thing and how they deal with it. I used "git reset
> --soft <big commit>^" and "git add -N" because there were new files,
> but it was clumsy.

To split a big commit, I simply reverse-diff-apply the changes that I
don't want in the big commit, and I stage all changes.  Then, I again
reverse-diff-apply all the staged changes, and keep that in the
unstaged portion.  Your repository should look like this now:

commit bigcommit
diff --git a/bigfile b/bigfile
+Desirable change
+Undesirable change

Staged changes:
diff --git a/bigfile b/bigfile
-Undesirable change

Unstaged changes:
diff --git a/bigfile b/bigfile
+Undesirable change

Now simply 'commit --amend' to remove the undesirable change from the
bigcommit, and commit the unstaged changes to produce a new
commit. Final result:

commit bigcommit
diff --git a/bigfile b/bigfile
+Desirable change

commit newcommit
diff --git a/bigfile b/bigfile
+Undesirable change

I can afford to do this kind of jugglery very easily because I use
Magit with Emacs.  After highlighting the relevant portions,
reverse-diff-apply is one keystroke :) But yes, you're probably right-
there should be an easier way to do this.  Maybe a 'git split' that
allows you to interactively select the portions of an existing commit
that you'd like to exclude from the commit and turn into a new commit?

Hope that helps.

-- Ram
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]