{"thread":{"id":"25063","subject":"git revert ignore whitespace","startedAt":"2010-09-10T07:57:52Z","lastAt":"2010-09-10T16:34:50Z","messageCount":5,"participants":["Steven","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"150428","messageId":"14756.91.183.48.98.1284105472.squirrel@stevenleeuw.kwik.to","threadId":"25063","inReplyTo":null,"subject":"git revert ignore whitespace","fromName":"Steven","fromEmail":"redalert.commander@gmail.com","sentAt":"2010-09-10T07:57:52Z","receivedAt":"2010-09-10T07:57:52Z","isPatch":false,"sender":{"key":"redalert.commander@gmail.com","avatar":null},"body":"Hi,\n\nPlease CC me, as I'm not subscribed to the list.\n\nI want to revert a specific commit using 'git revert',\nhowever in the meantime there were some whitespace changes.\nIs it still possible to do this? The manual doesn't mention a -w or\n--ignore-whitespace option for git revert.\n\nI'm using git 1.7.0.2 (msysgit)\n\nKind regards,\nSteven\n\n\n-- \nRarely do people communicate; they just take turns talking.\n"},{"id":"150438","messageId":"20100910142114.GB6936@sigill.intra.peff.net","threadId":"25063","inReplyTo":"14756.91.183.48.98.1284105472.squirrel@stevenleeuw.kwik.to","subject":"Re: git revert ignore whitespace","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-09-10T14:21:14Z","receivedAt":"2010-09-10T14:21:14Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Sep 10, 2010 at 09:57:52AM +0200, Steven wrote:\n\n> I want to revert a specific commit using 'git revert',\n> however in the meantime there were some whitespace changes.\n> Is it still possible to do this? The manual doesn't mention a -w or\n> --ignore-whitespace option for git revert.\n\nIn theory there is no reason we couldn't support \"-w\", but I don't think\nthere is a way to do it currently.\n\nYou could just manually do the revert. Something like:\n\n  git diff-tree -p $commit | git apply --ignore-whitespace\n  git commit -m \"revert '`git log -1 --format=%s $commit`'\"\n\nwhich is more or less what revert will do (actually, I think it will do\nmore with 3-way merges during the application, but the point is that a\nrevert in git is nothing more than achieving a tree state that pulls out\nthe reverted content, and then making a commit. It has no special status\nin the history graph).\n\n-Peff\n"},{"id":"150440","messageId":"15732.91.183.48.98.1284130451.squirrel@stevenleeuw.kwik.to","threadId":"25063","inReplyTo":"20100910142114.GB6936@sigill.intra.peff.net","subject":"Re: git revert ignore whitespace","fromName":"Steven","fromEmail":"redalert.commander@gmail.com","sentAt":"2010-09-10T14:54:11Z","receivedAt":"2010-09-10T14:54:11Z","isPatch":false,"sender":{"key":"redalert.commander@gmail.com","avatar":null},"body":"On Fri, September 10, 2010 16:21, Jeff King wrote:\n>\n> In theory there is no reason we couldn't support \"-w\", but I don't think\n> there is a way to do it currently.\n>\n> You could just manually do the revert. Something like:\n>\n>   git diff-tree -p $commit | git apply --ignore-whitespace\n>   git commit -m \"revert '`git log -1 --format=%s $commit`'\"\n>\n\nThanks for the tip Jeff.\n\nI had to modify the commands a bit to get it to work.\nHere they are:\ngit diff-tree -p <commithash> | git apply --reverse --ignore-whitespace -C0\ngit add <file(s)>\ngit commit -m \"revert '`git log -1 --format=%s $commit`'\"\n\nThe --reverse is necessary to revert a patch, I needed the -C0 parameter\nas well because the line above changed as well.\nThis was a fairly simple example, but I imagine it won't work at all with\na larger history, especially with more changes in the relevant sections\nand additions/deletions. I believe git revert does take these into\naccount?\n\nKind regards,\nSteven\n"},{"id":"150441","messageId":"20100910152434.GA8891@sigill.intra.peff.net","threadId":"25063","inReplyTo":"15732.91.183.48.98.1284130451.squirrel@stevenleeuw.kwik.to","subject":"Re: git revert ignore whitespace","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-09-10T15:24:34Z","receivedAt":"2010-09-10T15:24:34Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Sep 10, 2010 at 04:54:11PM +0200, Steven wrote:\n\n> > You could just manually do the revert. Something like:\n> >\n> >   git diff-tree -p $commit | git apply --ignore-whitespace\n> >   git commit -m \"revert '`git log -1 --format=%s $commit`'\"\n> \n> I had to modify the commands a bit to get it to work.\n> Here they are:\n> git diff-tree -p <commithash> | git apply --reverse --ignore-whitespace -C0\n> git add <file(s)>\n> git commit -m \"revert '`git log -1 --format=%s $commit`'\"\n>\n> The --reverse is necessary to revert a patch, I needed the -C0 parameter\n> as well because the line above changed as well.\n\nOops. Yeah, obviously I just typed that straight into the email and did\nnot actually run it. :) The --reverse is definitely necessary. Using -C0\ncan help, but it can also be dangerous, as context lines help apply make\nsure it's in the right spot.\n\n> This was a fairly simple example, but I imagine it won't work at all with\n> a larger history, especially with more changes in the relevant sections\n> and additions/deletions. I believe git revert does take these into\n> account?\n\nYeah, the question is really whether the reverse diff from the reverted\ncommit applies to your current tree. Nearby changes obviously make that\nharder.\n\nOnce upon a time revert itself was implemented like this (see 045f82c,\nwhich introduced revert and uses \"diff | apply\"). These days it is only\na little more complex. It uses the 3-way merge machinery, which should\ndo better with finding minimal conflicts when the context has changed,\nand will do rename detection (and when the patch doesn't apply, will\nactually put in conflict markers, which is a nice place to start with\nresolving it).\n\nRevert is written in C these days, but you can see the shell script\nversion using git-merge-recursive in contrib/examples/git-revert.sh.\nHowever, I don't think there is an easy way to ask merge-recursive to\nignore whitespace changes.\n\n-Peff\n"},{"id":"150452","messageId":"7vr5h1h80l.fsf@alter.siamese.dyndns.org","threadId":"25063","inReplyTo":"20100910152434.GA8891@sigill.intra.peff.net","subject":"Re: git revert ignore whitespace","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-09-10T16:34:50Z","receivedAt":"2010-09-10T16:34:50Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> Revert is written in C these days, but you can see the shell script\n> version using git-merge-recursive in contrib/examples/git-revert.sh.\n> However, I don't think there is an easy way to ask merge-recursive to\n> ignore whitespace changes.\n\nSee jf/merge-ignore-ws in 'pu' ;-)\n"}]}