git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* git revert ignore whitespace
@ 2010-09-10  7:57 Steven
  2010-09-10 14:21 ` Jeff King
  0 siblings, 1 reply; 5+ messages in thread
From: Steven @ 2010-09-10  7:57 UTC (permalink / raw)
  To: git

Hi,

Please CC me, as I'm not subscribed to the list.

I want to revert a specific commit using 'git revert',
however in the meantime there were some whitespace changes.
Is it still possible to do this? The manual doesn't mention a -w or
--ignore-whitespace option for git revert.

I'm using git 1.7.0.2 (msysgit)

Kind regards,
Steven


-- 
Rarely do people communicate; they just take turns talking.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: git revert ignore whitespace
  2010-09-10  7:57 git revert ignore whitespace Steven
@ 2010-09-10 14:21 ` Jeff King
  2010-09-10 14:54   ` Steven
  0 siblings, 1 reply; 5+ messages in thread
From: Jeff King @ 2010-09-10 14:21 UTC (permalink / raw)
  To: Steven; +Cc: git

On Fri, Sep 10, 2010 at 09:57:52AM +0200, Steven wrote:

> I want to revert a specific commit using 'git revert',
> however in the meantime there were some whitespace changes.
> Is it still possible to do this? The manual doesn't mention a -w or
> --ignore-whitespace option for git revert.

In theory there is no reason we couldn't support "-w", but I don't think
there is a way to do it currently.

You could just manually do the revert. Something like:

  git diff-tree -p $commit | git apply --ignore-whitespace
  git commit -m "revert '`git log -1 --format=%s $commit`'"

which is more or less what revert will do (actually, I think it will do
more with 3-way merges during the application, but the point is that a
revert in git is nothing more than achieving a tree state that pulls out
the reverted content, and then making a commit. It has no special status
in the history graph).

-Peff

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: git revert ignore whitespace
  2010-09-10 14:21 ` Jeff King
@ 2010-09-10 14:54   ` Steven
  2010-09-10 15:24     ` Jeff King
  0 siblings, 1 reply; 5+ messages in thread
From: Steven @ 2010-09-10 14:54 UTC (permalink / raw)
  To: Jeff King; +Cc: git

On Fri, September 10, 2010 16:21, Jeff King wrote:
>
> In theory there is no reason we couldn't support "-w", but I don't think
> there is a way to do it currently.
>
> You could just manually do the revert. Something like:
>
>   git diff-tree -p $commit | git apply --ignore-whitespace
>   git commit -m "revert '`git log -1 --format=%s $commit`'"
>

Thanks for the tip Jeff.

I had to modify the commands a bit to get it to work.
Here they are:
git diff-tree -p <commithash> | git apply --reverse --ignore-whitespace -C0
git add <file(s)>
git commit -m "revert '`git log -1 --format=%s $commit`'"

The --reverse is necessary to revert a patch, I needed the -C0 parameter
as well because the line above changed as well.
This was a fairly simple example, but I imagine it won't work at all with
a larger history, especially with more changes in the relevant sections
and additions/deletions. I believe git revert does take these into
account?

Kind regards,
Steven

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: git revert ignore whitespace
  2010-09-10 14:54   ` Steven
@ 2010-09-10 15:24     ` Jeff King
  2010-09-10 16:34       ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Jeff King @ 2010-09-10 15:24 UTC (permalink / raw)
  To: Steven; +Cc: git

On Fri, Sep 10, 2010 at 04:54:11PM +0200, Steven wrote:

> > You could just manually do the revert. Something like:
> >
> >   git diff-tree -p $commit | git apply --ignore-whitespace
> >   git commit -m "revert '`git log -1 --format=%s $commit`'"
> 
> I had to modify the commands a bit to get it to work.
> Here they are:
> git diff-tree -p <commithash> | git apply --reverse --ignore-whitespace -C0
> git add <file(s)>
> git commit -m "revert '`git log -1 --format=%s $commit`'"
>
> The --reverse is necessary to revert a patch, I needed the -C0 parameter
> as well because the line above changed as well.

Oops. Yeah, obviously I just typed that straight into the email and did
not actually run it. :) The --reverse is definitely necessary. Using -C0
can help, but it can also be dangerous, as context lines help apply make
sure it's in the right spot.

> This was a fairly simple example, but I imagine it won't work at all with
> a larger history, especially with more changes in the relevant sections
> and additions/deletions. I believe git revert does take these into
> account?

Yeah, the question is really whether the reverse diff from the reverted
commit applies to your current tree. Nearby changes obviously make that
harder.

Once upon a time revert itself was implemented like this (see 045f82c,
which introduced revert and uses "diff | apply"). These days it is only
a little more complex. It uses the 3-way merge machinery, which should
do better with finding minimal conflicts when the context has changed,
and will do rename detection (and when the patch doesn't apply, will
actually put in conflict markers, which is a nice place to start with
resolving it).

Revert is written in C these days, but you can see the shell script
version using git-merge-recursive in contrib/examples/git-revert.sh.
However, I don't think there is an easy way to ask merge-recursive to
ignore whitespace changes.

-Peff

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: git revert ignore whitespace
  2010-09-10 15:24     ` Jeff King
@ 2010-09-10 16:34       ` Junio C Hamano
  0 siblings, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2010-09-10 16:34 UTC (permalink / raw)
  To: Jeff King; +Cc: Steven, git

Jeff King <peff@peff.net> writes:

> Revert is written in C these days, but you can see the shell script
> version using git-merge-recursive in contrib/examples/git-revert.sh.
> However, I don't think there is an easy way to ask merge-recursive to
> ignore whitespace changes.

See jf/merge-ignore-ws in 'pu' ;-)

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-09-10 16:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-10  7:57 git revert ignore whitespace Steven
2010-09-10 14:21 ` Jeff King
2010-09-10 14:54   ` Steven
2010-09-10 15:24     ` Jeff King
2010-09-10 16:34       ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).