All of lore.kernel.org
 help / color / mirror / Atom feed
* How to effectively undo a part of a commit
@ 2007-03-01 16:33 Bill Lear
  2007-03-01 16:51 ` Simon 'corecode' Schubert
  0 siblings, 1 reply; 2+ messages in thread
From: Bill Lear @ 2007-03-01 16:33 UTC (permalink / raw)
  To: git

A colleague made a change to a file and committed it.  Then, he
made another change to the file and somehow undid the previous work,
then he committed the file.  Now, he would like to get the first change
he made and reapply it.

So, the changes look like this:

F1 -> delta 1 -> F2
F2 -> delta 2 -> F3

So, starting with F, he applies delta 1 to get F2.
Then, he applies delta 2 to get F3.

He says that using cvs he would do something like this:

% cvs update -j F1 -j F2

To apply delta 1 to F3.

We tried using git to get the delta 1 as a patch --- that went fine.
Then we used git-apply to apply the patch, but it refused, and it was
obvious that the line numbers of the patch no longer corresponded to
the line numbers in the file in his working tree.

Is there a way in git to do this, or is this an inherently unworkable
problem, as for some reason, I suspect?


Bill

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

* Re: How to effectively undo a part of a commit
  2007-03-01 16:33 How to effectively undo a part of a commit Bill Lear
@ 2007-03-01 16:51 ` Simon 'corecode' Schubert
  0 siblings, 0 replies; 2+ messages in thread
From: Simon 'corecode' Schubert @ 2007-03-01 16:51 UTC (permalink / raw)
  To: Bill Lear; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 1572 bytes --]

Bill Lear wrote:
> So, starting with F, he applies delta 1 to get F2.
> Then, he applies delta 2 to get F3.

And delta 2 reverts delta 1 again, right?

> He says that using cvs he would do something like this:
> 
> % cvs update -j F1 -j F2
> 
> To apply delta 1 to F3.

try git-cherry-pick -n F2.

> We tried using git to get the delta 1 as a patch --- that went fine.
> Then we used git-apply to apply the patch, but it refused, and it was
> obvious that the line numbers of the patch no longer corresponded to
> the line numbers in the file in his working tree.

patches 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.

> Is there a way in git to do this, or is this an inherently unworkable
> problem, as for some reason, I suspect?

there are plenty of ways.  i think you could also do something like this (untested):

git checkout F3
git branch fixF3 F1
git reset --soft fixF3
git commit
git checkout F2
git cherry-pick fixF3

which first transplants F3 back on F1, removing the delta which reverted F2.  then, having a nice patch now, applies it onto F2.

cheers
  simon

-- 
Serve - BSD     +++  RENT this banner advert  +++    ASCII Ribbon   /"\
Work - Mac      +++  space for low €€€ NOW!1  +++      Campaign     \ /
Party Enjoy Relax   |   http://dragonflybsd.org      Against  HTML   \
Dude 2c 2 the max   !   http://golden-apple.biz       Mail + News   / \


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]

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

end of thread, other threads:[~2007-03-01 16:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-01 16:33 How to effectively undo a part of a commit Bill Lear
2007-03-01 16:51 ` Simon 'corecode' Schubert

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.