git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Fedor Sergeev <Fedor.Sergeev@Sun.COM>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, Roman.Shaposhnick@Sun.COM
Subject: overly smart rebase - bug or feature?
Date: Tue, 11 Nov 2008 00:23:34 +0300	[thread overview]
Message-ID: <20081110212333.GU6799@sun.com> (raw)

Folks,

I have recently hit a behavior which might well be a feature, 
but it was very surprising (in a bad sense) to me.

I was trying to rebase a branch with changes in some file onto a branch
where this file was recently deleted. I would expect rebase to fail and 
suggest me to  resolve conflict manually.
However it somehow succeeded managing to find another file to patch instead 
of the initial one:

] cat git-rebase-bug.sh
#!/bin/sh
git init
# create three files with the same contents
perl -e ' for ($i=0; $i < 10; $i++) { print "$i\n" } ' >Makefile
cp Makefile Makefile1
cp Makefile Makefile2
git add .
git commit -m"created 3 makefiles"
# delete one file
git rm Makefile
git commit -m"deleted 1 makefile"
# go to another branch, one step back
git checkout -b mod HEAD^
# modify contents of the file deleted in master branch
echo "#10" >>Makefile
git add -u
git commit -m"modified 1 makefile"
# now rebase "mod" on top of "master" not expecting it to succeed
git rebase master mod
]

] mkdir git-bug; cd git-bug
] ../git-rebase-bug.sh
....
First, rewinding head to replay your work on top of it...
Applying: modified 1 makefile
error: Makefile: does not exist in index
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
]

Now if I look at the rebase result I see that it chose to patch "Makefile2" 
instead of my lovely "Makefile" (why not Makefile1, btw ;) ):

] git log --stat -1 --pretty=oneline
ce0101fc7884bce3eb9724b75d654e7c40abf0fd modified 1 makefile
 Makefile2 |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
]

I has always agreed with the claim that simple but reliable merge
(rebase, whatever) is much better than smartass one smarter than yourself.

And, to be honest, both merge and cherry-pick do not try to play smart:

] git reset --hard mod@{1}
] git checkout master
] git merge mod
CCONFLICT (delete/modify): Makefile deleted in HEAD and modified in mod. Version mod of Makefile left in tree.
Automatic merge failed; fix conflicts and then commit the result.
] git reset --hard
] git cherry-pick mod
Automatic cherry-pick failed.  After resolving the conflicts,
mark the corrected paths with 'git add <paths>' or 'git rm <paths>' and commit the result.
When commiting, use the option '-c f782a81' to retain authorship and message.
]

So, why rebase is smarter?

Yeah, and if it matters I tried it on 1.6.0.2 and 1.5.3.8 on Solaris and Linux.

best regards,
  Fedor.
PS I had problems reaching this list, thus ccing Junio explicitly.
I'm not on the list, btw..

             reply	other threads:[~2008-11-10 21:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-10 21:23 Fedor Sergeev [this message]
2008-11-10 23:14 ` overly smart rebase - bug or feature? Junio C Hamano
2008-11-10 23:31   ` Avery Pennarun
2008-11-10 23:36   ` Fedor Sergeev
2008-11-10 23:57     ` Junio C Hamano
2008-11-12 21:39   ` Fedor Sergeev
2008-11-12 22:04     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081110212333.GU6799@sun.com \
    --to=fedor.sergeev@sun.com \
    --cc=Roman.Shaposhnick@Sun.COM \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).