git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* preventing evil merges
@ 2013-05-30 16:34 Sandro Santilli
  2013-06-03 17:20 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Sandro Santilli @ 2013-05-30 16:34 UTC (permalink / raw)
  To: git

Hey all,
I've be burnt by what someone on IRC referred to as "evil merges",
that is loss of history after amending a merge commit:

 git merge anotherbranch
 git add something
 git commit --amend

After the steps above the addition of "something" can't be found in
the history anymore, but the file is there. Moreover (I think but
didn't try to reproruce) a further rebase to a common ancestore of
my working branch and "anotherbranch" resulted in further loss of
the changes. The only way for me to get them back has been by 
checking out from reflog.

I've no idea about what was going on but this experience reminded me
of another one I had in the past in which we could not figure out when
some changes were added into a repository (!).

If amending a merge is so dangerous, would it make sense to require
and hard-to-type switch in order for it to really do anything ?

--strk; 

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

* Re: preventing evil merges
  2013-05-30 16:34 preventing evil merges Sandro Santilli
@ 2013-06-03 17:20 ` Junio C Hamano
  2013-06-03 17:37   ` Antoine Pelisse
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2013-06-03 17:20 UTC (permalink / raw)
  To: Sandro Santilli; +Cc: git

Sandro Santilli <strk@keybit.net> writes:

>  git merge anotherbranch
>  git add something
>  git commit --amend
>
> After the steps above the addition of "something" can't be found in
> the history anymore, but the file is there.

This is a very common and sensible thing to do when dealing with
semantic conflict.  Imagine that you changed the name of a global
variable in the code on your current branch since the anotherbranch
you are pulling from forked from you.  Then imagine further that the 
anotherbranch added one location that refers to that variable.

Since they are not aware of the name change, they added the new
reference with the old variable name.  The part they added is a new
code, so it is very likely that there is no textual conflict when
you did "git merge anotherbranch".  But now the result is broken.

And you fix that semantic conflict by editing the file they added
the new reference to the variable under the old name and make it use
the variable with the new name.  You "git add something" and amend
the merge.

"git show" of the result will show you what happened, I think.

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

* Re: preventing evil merges
  2013-06-03 17:20 ` Junio C Hamano
@ 2013-06-03 17:37   ` Antoine Pelisse
  0 siblings, 0 replies; 3+ messages in thread
From: Antoine Pelisse @ 2013-06-03 17:37 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Sandro Santilli, git

On Mon, Jun 3, 2013 at 7:20 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Sandro Santilli <strk@keybit.net> writes:
>
>>  git merge anotherbranch
>>  git add something
>>  git commit --amend
>>
>> After the steps above the addition of "something" can't be found in
>> the history anymore, but the file is there.
>
> This is a very common and sensible thing to do when dealing with
> semantic conflict.  Imagine that you changed the name of a global
> variable in the code on your current branch since the anotherbranch
> you are pulling from forked from you.  Then imagine further that the
> anotherbranch added one location that refers to that variable.
>
> Since they are not aware of the name change, they added the new
> reference with the old variable name.  The part they added is a new
> code, so it is very likely that there is no textual conflict when
> you did "git merge anotherbranch".  But now the result is broken.
>
> And you fix that semantic conflict by editing the file they added
> the new reference to the variable under the old name and make it use
> the variable with the new name.  You "git add something" and amend
> the merge.
>
> "git show" of the result will show you what happened, I think.

Also, you need to use --cc option of log to see the change in history
(in addition to -p):

    git log --cc -p

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

end of thread, other threads:[~2013-06-03 17:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-30 16:34 preventing evil merges Sandro Santilli
2013-06-03 17:20 ` Junio C Hamano
2013-06-03 17:37   ` Antoine Pelisse

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).