{"thread":{"id":"26986","subject":"How to split a big commit","startedAt":"2011-04-04T11:52:45Z","lastAt":"2011-04-05T02:52:04Z","messageCount":6,"participants":["Nguyen Thai Ngoc Duy","Ramkumar Ramachandra","Jonathan Nieder","Lasse Makholm"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"165105","messageId":"BANLkTikFXzut7fY5Tr0u-abu5Q0rMUOCmA@mail.gmail.com","threadId":"26986","inReplyTo":null,"subject":"How to split a big commit","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2011-04-04T11:52:45Z","receivedAt":"2011-04-04T11:52:45Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"After a lot of small commits and a few mixed up large commits, it was\ntoo messy that I merged them all into one big commit then started\nspliting it into smaller, reasonable patches. Just wonder if anybody\nelse faces the same thing and how they deal with it. I used \"git reset\n--soft <big commit>^\" and \"git add -N\" because there were new files,\nbut it was clumsy.\n-- \nDuy\n"},{"id":"165111","messageId":"20110404130016.GA16975@kytes","threadId":"26986","inReplyTo":"BANLkTikFXzut7fY5Tr0u-abu5Q0rMUOCmA@mail.gmail.com","subject":"Re: How to split a big commit","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-04-04T13:00:20Z","receivedAt":"2011-04-04T13:00:20Z","isPatch":false,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi Nguyen,\n\nNguyen Thai Ngoc Duy writes:\n> After a lot of small commits and a few mixed up large commits, it was\n> too messy that I merged them all into one big commit then started\n> spliting it into smaller, reasonable patches. Just wonder if anybody\n> else faces the same thing and how they deal with it. I used \"git reset\n> --soft <big commit>^\" and \"git add -N\" because there were new files,\n> but it was clumsy.\n\nTo split a big commit, I simply reverse-diff-apply the changes that I\ndon't want in the big commit, and I stage all changes.  Then, I again\nreverse-diff-apply all the staged changes, and keep that in the\nunstaged portion.  Your repository should look like this now:\n\ncommit bigcommit\ndiff --git a/bigfile b/bigfile\n+Desirable change\n+Undesirable change\n\nStaged changes:\ndiff --git a/bigfile b/bigfile\n-Undesirable change\n\nUnstaged changes:\ndiff --git a/bigfile b/bigfile\n+Undesirable change\n\nNow simply 'commit --amend' to remove the undesirable change from the\nbigcommit, and commit the unstaged changes to produce a new\ncommit. Final result:\n\ncommit bigcommit\ndiff --git a/bigfile b/bigfile\n+Desirable change\n\ncommit newcommit\ndiff --git a/bigfile b/bigfile\n+Undesirable change\n\nI can afford to do this kind of jugglery very easily because I use\nMagit with Emacs.  After highlighting the relevant portions,\nreverse-diff-apply is one keystroke :) But yes, you're probably right-\nthere should be an easier way to do this.  Maybe a 'git split' that\nallows you to interactively select the portions of an existing commit\nthat you'd like to exclude from the commit and turn into a new commit?\n\nHope that helps.\n\n-- Ram\n"},{"id":"165112","messageId":"BANLkTinpiR2sHS35uqD+uLnTKVtimhT7eg@mail.gmail.com","threadId":"26986","inReplyTo":"20110404130016.GA16975@kytes","subject":"Re: How to split a big commit","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2011-04-04T14:25:38Z","receivedAt":"2011-04-04T14:25:38Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Mon, Apr 4, 2011 at 8:00 PM, Ramkumar Ramachandra <artagnon@gmail.com> wrote:\n> To split a big commit, I simply reverse-diff-apply the changes that I\n> don't want in the big commit, and I stage all changes.  Then, I again\n> reverse-diff-apply all the staged changes, and keep that in the\n> unstaged portion.\n\nWon't work for me. The reverse part would be way larger than the to-commit part.\n\n> ...\n> I can afford to do this kind of jugglery very easily because I use\n> Magit with Emacs.  After highlighting the relevant portions,\n> reverse-diff-apply is one keystroke :)\n\nHmm.. interesting. Never got around to actually use magit. I may have\na good reason now.\n\n> But yes, you're probably right-\n> there should be an easier way to do this.  Maybe a 'git split' that\n> allows you to interactively select the portions of an existing commit\n> that you'd like to exclude from the commit and turn into a new commit?\n\nHmm..yeah something like grep for chunks, then automatically splitting\nthose chunks out would be nice.\n\nI have another use for such a tool too. When .po files are\nautomatically updated by intltool (gnome translation helper tool),\ncomment lines are all changed because they contain source line and\nthose line likely change. With this tool I can filter out comment-only\nchanges.\n\nThanks for the idea.\n-- \nDuy\n"},{"id":"165147","messageId":"20110405000852.GA1704@elie","threadId":"26986","inReplyTo":"BANLkTikFXzut7fY5Tr0u-abu5Q0rMUOCmA@mail.gmail.com","subject":"Re: How to split a big commit","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-04-05T00:08:52Z","receivedAt":"2011-04-05T00:08:52Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi Duy,\n\nNguyen Thai Ngoc Duy wrote:\n\n> After a lot of small commits and a few mixed up large commits, it was\n> too messy that I merged them all into one big commit then started\n> spliting it into smaller, reasonable patches. Just wonder if anybody\n> else faces the same thing and how they deal with it. I used \"git reset\n> --soft <big commit>^\" and \"git add -N\" because there were new files,\n> but it was clumsy.\n\nI tend to do \"git reset HEAD^ -- .\" and then \"git add -N .\" and\n\"git add -p\", for what it's worth.\n"},{"id":"165160","messageId":"BANLkTikZ_-OE1u_T+wGkYa3cSN0-KL-bGg@mail.gmail.com","threadId":"26986","inReplyTo":"20110405000852.GA1704@elie","subject":"Re: How to split a big commit","fromName":"Lasse Makholm","fromEmail":"lasse.makholm@gmail.com","sentAt":"2011-04-05T02:31:54Z","receivedAt":"2011-04-05T02:31:54Z","isPatch":false,"sender":{"key":"lasse.makholm@gmail.com","avatar":"https://gravatar.com/avatar/5bc3a34e4fa8ba26b38c333f370b15c034351e18e09b056a2608f3904ae1a4c1?d=mp&s=160"},"body":"On 5 April 2011 02:08, Jonathan Nieder <jrnieder@gmail.com> wrote:\n> Hi Duy,\n>\n> Nguyen Thai Ngoc Duy wrote:\n>\n>> After a lot of small commits and a few mixed up large commits, it was\n>> too messy that I merged them all into one big commit then started\n>> spliting it into smaller, reasonable patches. Just wonder if anybody\n>> else faces the same thing and how they deal with it. I used \"git reset\n>> --soft <big commit>^\" and \"git add -N\" because there were new files,\n>> but it was clumsy.\n>\n> I tend to do \"git reset HEAD^ -- .\" and then \"git add -N .\" and\n> \"git add -p\", for what it's worth.\n\nIn addition, after you've added some hunks, use git stash to stow away\nall the other changes to test each new commit seperately.\n\n/Lasse\n"},{"id":"165162","messageId":"BANLkTim5j8cezy8jhs9dqPXYJRkRGf0GMA@mail.gmail.com","threadId":"26986","inReplyTo":"20110405000852.GA1704@elie","subject":"Re: How to split a big commit","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2011-04-05T02:52:04Z","receivedAt":"2011-04-05T02:52:04Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Tue, Apr 5, 2011 at 7:08 AM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n> Hi Duy,\n>\n> Nguyen Thai Ngoc Duy wrote:\n>\n>> After a lot of small commits and a few mixed up large commits, it was\n>> too messy that I merged them all into one big commit then started\n>> spliting it into smaller, reasonable patches. Just wonder if anybody\n>> else faces the same thing and how they deal with it. I used \"git reset\n>> --soft <big commit>^\" and \"git add -N\" because there were new files,\n>> but it was clumsy.\n>\n> I tend to do \"git reset HEAD^ -- .\" and then \"git add -N .\" and\n> \"git add -p\", for what it's worth.\n\nBut you would need to undo \"git add -N\" for those files you don't want in yet?\n-- \nDuy\n"}]}