{"thread":{"id":"7040","subject":"How to effectively undo a part of a commit","startedAt":"2007-03-01T16:33:12Z","lastAt":"2007-03-01T16:51:58Z","messageCount":2,"participants":["Bill Lear","Simon 'corecode' Schubert"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"35983","messageId":"17895.72.525085.734138@lisa.zopyra.com","threadId":"7040","inReplyTo":null,"subject":"How to effectively undo a part of a commit","fromName":"Bill Lear","fromEmail":"rael@zopyra.com","sentAt":"2007-03-01T16:33:12Z","receivedAt":"2007-03-01T16:33:12Z","isPatch":false,"sender":{"key":"rael@zopyra.com","avatar":"https://gravatar.com/avatar/c4f2d2790ca3828d3b4e7dfebabf61d2fe94fd82fa49cdac2a5295dd2d46a874?d=mp&s=160"},"body":"A colleague made a change to a file and committed it.  Then, he\nmade another change to the file and somehow undid the previous work,\nthen he committed the file.  Now, he would like to get the first change\nhe made and reapply it.\n\nSo, the changes look like this:\n\nF1 -> delta 1 -> F2\nF2 -> delta 2 -> F3\n\nSo, starting with F, he applies delta 1 to get F2.\nThen, he applies delta 2 to get F3.\n\nHe says that using cvs he would do something like this:\n\n% cvs update -j F1 -j F2\n\nTo apply delta 1 to F3.\n\nWe tried using git to get the delta 1 as a patch --- that went fine.\nThen we used git-apply to apply the patch, but it refused, and it was\nobvious that the line numbers of the patch no longer corresponded to\nthe line numbers in the file in his working tree.\n\nIs there a way in git to do this, or is this an inherently unworkable\nproblem, as for some reason, I suspect?\n\n\nBill\n"},{"id":"35985","messageId":"45E704AE.6000904@fs.ei.tum.de","threadId":"7040","inReplyTo":"17895.72.525085.734138@lisa.zopyra.com","subject":"Re: How to effectively undo a part of a commit","fromName":"Simon 'corecode' Schubert","fromEmail":"corecode@fs.ei.tum.de","sentAt":"2007-03-01T16:51:58Z","receivedAt":"2007-03-01T16:51:58Z","isPatch":false,"sender":{"key":"corecode@fs.ei.tum.de","avatar":"https://gravatar.com/avatar/eff9dbf0cdac0d1e6a6cd7ed0e50763edcb376b493b5253a35ff167918ad79e1?d=mp&s=160"},"body":"Bill Lear wrote:\n> So, starting with F, he applies delta 1 to get F2.\n> Then, he applies delta 2 to get F3.\n\nAnd delta 2 reverts delta 1 again, right?\n\n> He says that using cvs he would do something like this:\n> \n> % cvs update -j F1 -j F2\n> \n> To apply delta 1 to F3.\n\ntry git-cherry-pick -n F2.\n\n> We tried using git to get the delta 1 as a patch --- that went fine.\n> Then we used git-apply to apply the patch, but it refused, and it was\n> obvious that the line numbers of the patch no longer corresponded to\n> the line numbers in the file in his working tree.\n\npatches don't care about line numbers (at least not so much).  you probably have overlapping changes, so apply can't work without generating a collision.  try git-apply --reject and then merge the .rej file.\n\n> Is there a way in git to do this, or is this an inherently unworkable\n> problem, as for some reason, I suspect?\n\nthere are plenty of ways.  i think you could also do something like this (untested):\n\ngit checkout F3\ngit branch fixF3 F1\ngit reset --soft fixF3\ngit commit\ngit checkout F2\ngit cherry-pick fixF3\n\nwhich first transplants F3 back on F1, removing the delta which reverted F2.  then, having a nice patch now, applies it onto F2.\n\ncheers\n  simon\n\n-- \nServe - BSD     +++  RENT this banner advert  +++    ASCII Ribbon   /\"\\\nWork - Mac      +++  space for low €€€ NOW!1  +++      Campaign     \\ /\nParty Enjoy Relax   |   http://dragonflybsd.org      Against  HTML   \\\nDude 2c 2 the max   !   http://golden-apple.biz       Mail + News   / \\\n\n"}]}