All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC] rebase: add --revisions flag
@ 2009-12-08 14:47 Michael S. Tsirkin
  2009-12-08 16:08 ` Björn Steinbrink
  2009-12-08 20:22 ` Junio C Hamano
  0 siblings, 2 replies; 43+ messages in thread
From: Michael S. Tsirkin @ 2009-12-08 14:47 UTC (permalink / raw)
  To: git, Junio C Hamano

Add --revisions flag to rebase, so that it can be used
to apply an arbitrary range of commits on top
of a current branch.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---

I've been wishing for this functionality for a while now,
so here goes. This isn't yet properly documented and I didn't
write a test, but the patch seems to work fine for me.
Any early flames/feedback?


 git-rebase.sh |   36 ++++++++++++++++++++++++------------
 1 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/git-rebase.sh b/git-rebase.sh
index b121f45..d99d04b 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -3,12 +3,13 @@
 # Copyright (c) 2005 Junio C Hamano.
 #
 
-USAGE='[--interactive | -i] [-v] [--force-rebase | -f] [--onto <newbase>] [<upstream>|--root] [<branch>] [--quiet | -q]'
+USAGE='[--interactive | -i] [-v] [--force-rebase | -f] [--onto <newbase>] [--revisions <revision range>] [<upstream>|--root] [<branch>] [--quiet | -q]'
 LONG_USAGE='git-rebase replaces <branch> with a new branch of the
 same name.  When the --onto option is provided the new branch starts
 out with a HEAD equal to <newbase>, otherwise it is equal to <upstream>
 It then attempts to create a new commit for each commit from the original
-<branch> that does not exist in the <upstream> branch.
+<branch> that does not exist in the <upstream> branch, or for
+each commit matching <revision range> when the --revisions options is provided.
 
 It is possible that a merge failure will prevent this process from being
 completely automatic.  You will have to resolve any such merge failure
@@ -41,6 +42,7 @@ If you would prefer to skip this patch, instead run \"git rebase --skip\".
 To restore the original branch and stop rebasing run \"git rebase --abort\".
 "
 unset newbase
+unset revisions
 strategy=recursive
 do_merge=
 dotest="$GIT_DIR"/rebase-merge
@@ -291,6 +293,11 @@ do
 		newbase="$2"
 		shift
 		;;
+	--revisions)
+		test 2 -le "$#" || usage
+		revisions="$2"
+		shift
+		;;
 	-M|-m|--m|--me|--mer|--merg|--merge)
 		do_merge=t
 		;;
@@ -459,12 +466,24 @@ case "$#" in
 esac
 orig_head=$branch
 
+if test -z "$revisions"
+then
+	if test -n "$rebase_root"
+	then
+		revisions="$onto..$orig_head"
+	else
+		revisions="$upstream..$orig_head"
+	fi
+	mb=$(git merge-base "$onto" "$branch")
+else
+	mb=""
+fi
+
 # Now we are rebasing commits $upstream..$branch (or with --root,
 # everything leading up to $branch) on top of $onto
 
 # Check if we are already based on $onto with linear history,
 # but this should be done only when upstream and onto are the same.
-mb=$(git merge-base "$onto" "$branch")
 if test "$upstream" = "$onto" && test "$mb" = "$onto" &&
 	# linear history?
 	! (git rev-list --parents "$onto".."$branch" | sane_grep " .* ") > /dev/null
@@ -489,10 +508,10 @@ if test -n "$diffstat"
 then
 	if test -n "$verbose"
 	then
-		echo "Changes from $mb to $onto:"
+		echo "Changes $revisions:"
 	fi
 	# We want color (if set), but no pager
-	GIT_PAGER='' git diff --stat --summary "$mb" "$onto"
+	GIT_PAGER='' git diff --stat --summary "$revisions"
 fi
 
 # If the $onto is a proper descendant of the tip of the branch, then
@@ -504,13 +523,6 @@ then
 	exit 0
 fi
 
-if test -n "$rebase_root"
-then
-	revisions="$onto..$orig_head"
-else
-	revisions="$upstream..$orig_head"
-fi
-
 if test -z "$do_merge"
 then
 	git format-patch -k --stdout --full-index --ignore-if-in-upstream \
-- 
1.6.6.rc1.43.gf55cc

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-08 14:47 [PATCH RFC] rebase: add --revisions flag Michael S. Tsirkin
@ 2009-12-08 16:08 ` Björn Steinbrink
  2009-12-08 16:11   ` Michael S. Tsirkin
  2009-12-08 16:14   ` Michael S. Tsirkin
  2009-12-08 20:22 ` Junio C Hamano
  1 sibling, 2 replies; 43+ messages in thread
From: Björn Steinbrink @ 2009-12-08 16:08 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: git, Junio C Hamano

On 2009.12.08 16:47:42 +0200, Michael S. Tsirkin wrote:
> Add --revisions flag to rebase, so that it can be used
> to apply an arbitrary range of commits on top
> of a current branch.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
> 
> I've been wishing for this functionality for a while now,
> so here goes. This isn't yet properly documented and I didn't
> write a test, but the patch seems to work fine for me.
> Any early flames/feedback?

This pretty much reverses what rebase normally does. Instead of "rebase
this onto that" it's "'rebase' that onto this". And instead of updating
the branch head that got rebased, the, uhm, "upstream" gets updated.

Also, AFAICT this needs to be called like this:
git rebase --revisions foo..bar HEAD

Changing the meaning of the <upstream> argument and relying on the fact
that <newbase> defaults to <upstream>. If such a thing gets added, it
should rather work like --root, not using <upstream> at all, but --onto
<newbase> only. Maybe defaulting to HEAD for <newbase> and making --onto
optional, as it's reversed WRT what it does compared to the usual
rebase.

But generally, I'd say it would be better to add such a range feature to
cherry-pick than abusing rebase for that.

Björn

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-08 16:08 ` Björn Steinbrink
@ 2009-12-08 16:11   ` Michael S. Tsirkin
  2009-12-08 16:41     ` Björn Steinbrink
  2009-12-08 16:14   ` Michael S. Tsirkin
  1 sibling, 1 reply; 43+ messages in thread
From: Michael S. Tsirkin @ 2009-12-08 16:11 UTC (permalink / raw)
  To: Björn Steinbrink; +Cc: git, Junio C Hamano

On Tue, Dec 08, 2009 at 05:08:22PM +0100, Björn Steinbrink wrote:
> On 2009.12.08 16:47:42 +0200, Michael S. Tsirkin wrote:
> > Add --revisions flag to rebase, so that it can be used
> > to apply an arbitrary range of commits on top
> > of a current branch.
> > 
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> > 
> > I've been wishing for this functionality for a while now,
> > so here goes. This isn't yet properly documented and I didn't
> > write a test, but the patch seems to work fine for me.
> > Any early flames/feedback?
> 
> This pretty much reverses what rebase normally does. Instead of "rebase
> this onto that" it's "'rebase' that onto this". And instead of updating
> the branch head that got rebased, the, uhm, "upstream" gets updated.
> 
> Also, AFAICT this needs to be called like this:
> git rebase --revisions foo..bar HEAD
> 
> Changing the meaning of the <upstream> argument and relying on the fact
> that <newbase> defaults to <upstream>. If such a thing gets added, it
> should rather work like --root, not using <upstream> at all, but --onto
> <newbase> only. Maybe defaulting to HEAD for <newbase> and making --onto
> optional, as it's reversed WRT what it does compared to the usual
> rebase.

Sorry, I had trouble parsing the above.  Could you suggest e.g. how the
help line should look?

> But generally, I'd say it would be better to add such a range feature to
> cherry-pick than abusing rebase for that.
> 
> Björn

The reason to use rebase is that I often want to combine
this with -i flag, editing patches as they are applied.

-- 
MST

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-08 16:08 ` Björn Steinbrink
  2009-12-08 16:11   ` Michael S. Tsirkin
@ 2009-12-08 16:14   ` Michael S. Tsirkin
  2009-12-08 16:37     ` Björn Steinbrink
  1 sibling, 1 reply; 43+ messages in thread
From: Michael S. Tsirkin @ 2009-12-08 16:14 UTC (permalink / raw)
  To: Björn Steinbrink; +Cc: git, Junio C Hamano

On Tue, Dec 08, 2009 at 05:08:22PM +0100, Björn Steinbrink wrote:
> On 2009.12.08 16:47:42 +0200, Michael S. Tsirkin wrote:
> > Add --revisions flag to rebase, so that it can be used
> > to apply an arbitrary range of commits on top
> > of a current branch.
> > 
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> > 
> > I've been wishing for this functionality for a while now,
> > so here goes. This isn't yet properly documented and I didn't
> > write a test, but the patch seems to work fine for me.
> > Any early flames/feedback?
> 
> This pretty much reverses what rebase normally does. Instead of "rebase
> this onto that" it's "'rebase' that onto this". And instead of updating
> the branch head that got rebased, the, uhm, "upstream" gets updated.

The last sentence is wrong I think - it is still the branch head that
is updated.

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-08 16:14   ` Michael S. Tsirkin
@ 2009-12-08 16:37     ` Björn Steinbrink
  2009-12-08 16:44       ` Michael S. Tsirkin
  0 siblings, 1 reply; 43+ messages in thread
From: Björn Steinbrink @ 2009-12-08 16:37 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: git, Junio C Hamano

On 2009.12.08 18:14:07 +0200, Michael S. Tsirkin wrote:
> On Tue, Dec 08, 2009 at 05:08:22PM +0100, Björn Steinbrink wrote:
> > On 2009.12.08 16:47:42 +0200, Michael S. Tsirkin wrote:
> > > Add --revisions flag to rebase, so that it can be used
> > > to apply an arbitrary range of commits on top
> > > of a current branch.
> > > 
> > > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > > ---
> > > 
> > > I've been wishing for this functionality for a while now,
> > > so here goes. This isn't yet properly documented and I didn't
> > > write a test, but the patch seems to work fine for me.
> > > Any early flames/feedback?
> > 
> > This pretty much reverses what rebase normally does. Instead of "rebase
> > this onto that" it's "'rebase' that onto this". And instead of updating
> > the branch head that got rebased, the, uhm, "upstream" gets updated.
> 
> The last sentence is wrong I think - it is still the branch head that
> is updated.

But you don't rebase the branch head. Before the rebase, the branch head
doesn't reference the commits that get rebased. For example:

git checkout bar
git rebase --revisions foo bar

You "rebase" the commits in foo's history, but you update bar.

WRT the result, the above command should be equivalent to:
git checkout bar
git reset --hard foo
git rebase --root --onto ORIG_HEAD;

And here, the commits currently reachable through "bar" are rebased, and
"bar" also gets updated.

Björn

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-08 16:11   ` Michael S. Tsirkin
@ 2009-12-08 16:41     ` Björn Steinbrink
  2009-12-08 16:49       ` Michael S. Tsirkin
  0 siblings, 1 reply; 43+ messages in thread
From: Björn Steinbrink @ 2009-12-08 16:41 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: git, Junio C Hamano

On 2009.12.08 18:11:44 +0200, Michael S. Tsirkin wrote:
> On Tue, Dec 08, 2009 at 05:08:22PM +0100, Björn Steinbrink wrote:
> > On 2009.12.08 16:47:42 +0200, Michael S. Tsirkin wrote:
> > > Add --revisions flag to rebase, so that it can be used
> > > to apply an arbitrary range of commits on top
> > > of a current branch.
> > > 
> > > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > > ---
> > > 
> > > I've been wishing for this functionality for a while now,
> > > so here goes. This isn't yet properly documented and I didn't
> > > write a test, but the patch seems to work fine for me.
> > > Any early flames/feedback?
> > 
> > This pretty much reverses what rebase normally does. Instead of "rebase
> > this onto that" it's "'rebase' that onto this". And instead of updating
> > the branch head that got rebased, the, uhm, "upstream" gets updated.
> > 
> > Also, AFAICT this needs to be called like this:
> > git rebase --revisions foo..bar HEAD
> > 
> > Changing the meaning of the <upstream> argument and relying on the fact
> > that <newbase> defaults to <upstream>. If such a thing gets added, it
> > should rather work like --root, not using <upstream> at all, but --onto
> > <newbase> only. Maybe defaulting to HEAD for <newbase> and making --onto
> > optional, as it's reversed WRT what it does compared to the usual
> > rebase.
> 
> Sorry, I had trouble parsing the above.  Could you suggest e.g. how the
> help line should look?

Current:
git rebase [-i | --interactive] [options] [--onto <newbase>]
	<upstream> [<branch>]
git rebase [-i | --interactive] [options] --onto <newbase>
	--root [<branch>]

Add:
git rebase [-i | --interactive] [options] --revisions <range> [<branch>]

(Thinking about it, I guess an explicit --onto makes no sense with the
--revisions flag)

> > But generally, I'd say it would be better to add such a range feature to
> > cherry-pick than abusing rebase for that.
> 
> The reason to use rebase is that I often want to combine
> this with -i flag, editing patches as they are applied.

Hm, well, your patch didn't touch git-rebase--interactive.sh ;-)

Björn

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-08 16:37     ` Björn Steinbrink
@ 2009-12-08 16:44       ` Michael S. Tsirkin
  2009-12-08 19:11         ` Björn Steinbrink
  2009-12-09  4:51         ` Miles Bader
  0 siblings, 2 replies; 43+ messages in thread
From: Michael S. Tsirkin @ 2009-12-08 16:44 UTC (permalink / raw)
  To: Björn Steinbrink; +Cc: git, Junio C Hamano

On Tue, Dec 08, 2009 at 05:37:37PM +0100, Björn Steinbrink wrote:
> On 2009.12.08 18:14:07 +0200, Michael S. Tsirkin wrote:
> > On Tue, Dec 08, 2009 at 05:08:22PM +0100, Björn Steinbrink wrote:
> > > On 2009.12.08 16:47:42 +0200, Michael S. Tsirkin wrote:
> > > > Add --revisions flag to rebase, so that it can be used
> > > > to apply an arbitrary range of commits on top
> > > > of a current branch.
> > > > 
> > > > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > > > ---
> > > > 
> > > > I've been wishing for this functionality for a while now,
> > > > so here goes. This isn't yet properly documented and I didn't
> > > > write a test, but the patch seems to work fine for me.
> > > > Any early flames/feedback?
> > > 
> > > This pretty much reverses what rebase normally does. Instead of "rebase
> > > this onto that" it's "'rebase' that onto this". And instead of updating
> > > the branch head that got rebased, the, uhm, "upstream" gets updated.
> > 
> > The last sentence is wrong I think - it is still the branch head that
> > is updated.
> 
> But you don't rebase the branch head. Before the rebase, the branch head
> doesn't reference the commits that get rebased. For example:
> 
> git checkout bar
> git rebase --revisions foo bar
> 
> You "rebase" the commits in foo's history, but you update bar.

Yes, that's the who point of the patch.  The above applies a single
commit, foo, on top of current branch bar.

> WRT the result, the above command should be equivalent to:
> git checkout bar
> git reset --hard foo
> git rebase --root --onto ORIG_HEAD;
> 
> And here, the commits currently reachable through "bar" are rebased, and
> "bar" also gets updated.
> 
> Björn

So this 
1. won't be very useful, as you show it is easy
   to achieve with existing commands.
2. interprets "foo" as branch name as opposed to
   revision range.

OTOH, rebase --revisions as I implemented is a "smarter cherry-pick" which
can't easily be achieved with existing commands, especially if you add
"-i".


-- 
MST

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-08 16:41     ` Björn Steinbrink
@ 2009-12-08 16:49       ` Michael S. Tsirkin
  2009-12-08 19:13         ` Björn Steinbrink
  0 siblings, 1 reply; 43+ messages in thread
From: Michael S. Tsirkin @ 2009-12-08 16:49 UTC (permalink / raw)
  To: Björn Steinbrink; +Cc: git, Junio C Hamano

On Tue, Dec 08, 2009 at 05:41:13PM +0100, Björn Steinbrink wrote:
> On 2009.12.08 18:11:44 +0200, Michael S. Tsirkin wrote:
> > On Tue, Dec 08, 2009 at 05:08:22PM +0100, Björn Steinbrink wrote:
> > > On 2009.12.08 16:47:42 +0200, Michael S. Tsirkin wrote:
> > > > Add --revisions flag to rebase, so that it can be used
> > > > to apply an arbitrary range of commits on top
> > > > of a current branch.
> > > > 
> > > > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > > > ---
> > > > 
> > > > I've been wishing for this functionality for a while now,
> > > > so here goes. This isn't yet properly documented and I didn't
> > > > write a test, but the patch seems to work fine for me.
> > > > Any early flames/feedback?
> > > 
> > > This pretty much reverses what rebase normally does. Instead of "rebase
> > > this onto that" it's "'rebase' that onto this". And instead of updating
> > > the branch head that got rebased, the, uhm, "upstream" gets updated.
> > > 
> > > Also, AFAICT this needs to be called like this:
> > > git rebase --revisions foo..bar HEAD
> > > 
> > > Changing the meaning of the <upstream> argument and relying on the fact
> > > that <newbase> defaults to <upstream>. If such a thing gets added, it
> > > should rather work like --root, not using <upstream> at all, but --onto
> > > <newbase> only. Maybe defaulting to HEAD for <newbase> and making --onto
> > > optional, as it's reversed WRT what it does compared to the usual
> > > rebase.
> > 
> > Sorry, I had trouble parsing the above.  Could you suggest e.g. how the
> > help line should look?
> 
> Current:
> git rebase [-i | --interactive] [options] [--onto <newbase>]
> 	<upstream> [<branch>]
> git rebase [-i | --interactive] [options] --onto <newbase>
> 	--root [<branch>]
> 
> Add:
> git rebase [-i | --interactive] [options] --revisions <range> [<branch>]
> 
> (Thinking about it, I guess an explicit --onto makes no sense with the
> --revisions flag)

I agree.
So this is different from what I implemented basically only in that
we should disallow combining --onto with --revisions. Right?

> > > But generally, I'd say it would be better to add such a range feature to
> > > cherry-pick than abusing rebase for that.
> > 
> > The reason to use rebase is that I often want to combine
> > this with -i flag, editing patches as they are applied.
> 
> Hm, well, your patch didn't touch git-rebase--interactive.sh ;-)
> 
> Björn

Ah, I was wondering why it doesn't work :)

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-08 16:44       ` Michael S. Tsirkin
@ 2009-12-08 19:11         ` Björn Steinbrink
  2009-12-08 20:00           ` Michael S. Tsirkin
  2009-12-09  4:51         ` Miles Bader
  1 sibling, 1 reply; 43+ messages in thread
From: Björn Steinbrink @ 2009-12-08 19:11 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: git, Junio C Hamano

On 2009.12.08 18:44:49 +0200, Michael S. Tsirkin wrote:
> On Tue, Dec 08, 2009 at 05:37:37PM +0100, Björn Steinbrink wrote:
> > On 2009.12.08 18:14:07 +0200, Michael S. Tsirkin wrote:
> > > On Tue, Dec 08, 2009 at 05:08:22PM +0100, Björn Steinbrink wrote:
> > > > On 2009.12.08 16:47:42 +0200, Michael S. Tsirkin wrote:
> > > > > Add --revisions flag to rebase, so that it can be used
> > > > > to apply an arbitrary range of commits on top
> > > > > of a current branch.
> > > > > 
> > > > > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > > > > ---
> > > > > 
> > > > > I've been wishing for this functionality for a while now,
> > > > > so here goes. This isn't yet properly documented and I didn't
> > > > > write a test, but the patch seems to work fine for me.
> > > > > Any early flames/feedback?
> > > > 
> > > > This pretty much reverses what rebase normally does. Instead of "rebase
> > > > this onto that" it's "'rebase' that onto this". And instead of updating
> > > > the branch head that got rebased, the, uhm, "upstream" gets updated.
> > > 
> > > The last sentence is wrong I think - it is still the branch head that
> > > is updated.
> > 
> > But you don't rebase the branch head. Before the rebase, the branch head
> > doesn't reference the commits that get rebased. For example:
> > 
> > git checkout bar
> > git rebase --revisions foo bar
> > 
> > You "rebase" the commits in foo's history, but you update bar.
> 
> Yes, that's the who point of the patch.

Yes, and it's "backwards" compared to the existing "rebase" modes, but
more like "cherry-pick".

> The above applies a single commit, foo, on top of current branch bar.

Hm, no. I expected it to turn all commits reachable from foo into
patches and applying them to bar. But actually, that should hit the
special <since> mode of format-patch. So
git rebase --revisions foo bar
is (with your patch) actually the same as
git rebase foo bar

So actually the example should have been:
git rebase --root --revisions foo bar

Both invocations probably mess up the diff-stat as that becomes:
git diff --stat --summary foo
So it creates a diffstat of the diff from the working tree to "foo",
which can't be right.

> 
> > WRT the result, the above command should be equivalent to:
> > git checkout bar
> > git reset --hard foo
> > git rebase --root --onto ORIG_HEAD;
> > 
> > And here, the commits currently reachable through "bar" are rebased, and
> > "bar" also gets updated.
> 
> So this 
> 1. won't be very useful, as you show it is easy
>    to achieve with existing commands.

One can "almost" achieve it.
git rebase --revision A..B foo

is about the same as:
git checkout foo
git reset --hard B
git rebase --onto ORIG_HEAD A

But:
a) The "reset --hard" obviously lacks the safety checks for clean
index/working tree.
b) "git rebase --abort" won't take you back to your initial state, but
to B.
c) It's not really obvious that you can do it and how to do it.

Another possibility would be:

git checkout B^0 # detach HEAD at B
git rebase foo # rebase onto foo
git checkout foo 
git merge HEAD@{1} # Fast-forwards foo to the rebased stuff

That fixes a), avoid b) [because you don't mess up any branch head
early] but is still subject to c).

And for both methods, the ORIG_HEAD and HEAD@{1} arguments are somewhat
"unstable", e.g. checking out the wrong branch head first, and only then
the correct one, you'd have to use HEAD@{2} instead of HEAD@{1} (because
the reflog for HEAD got a new entry).

So you can already do what you want to do, but wrapping it in a single
porcelain might still be useful because it's obviously a  lot easier and
safer that way. That said, I wonder what kind of workflow you're using
though, and why you require that feature. I've never needed something
like that.

> 2. interprets "foo" as branch name as opposed to
>    revision range.

Well, a single committish is a "range" as far as the range-based
commands are concerned, e.g. "git log master" treats "master" to mean
all commits reachable it. If "rebase --revisions master" would do the
same, that's at least consistent (and for single commit picks, there's
already cherry-pick). The problem with your patch is that it passes the
revision argument to format-patch as is, and:
git format-patch foo
is the same as
git format-patch foo..HEAD


> OTOH, rebase --revisions as I implemented is a "smarter cherry-pick"
> which can't easily be achieved with existing commands, especially if
> you add "-i".

And that "is a 'smarter cherry-pick'" is why I think that rebase is
actually the wrong command to get that feature. While rebase internally
does just mass-cherry-picking, it does that with commits in the current
branch onto a specified branch. The --revisions flag makes it do things
the other way around.

Björn

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-08 16:49       ` Michael S. Tsirkin
@ 2009-12-08 19:13         ` Björn Steinbrink
  0 siblings, 0 replies; 43+ messages in thread
From: Björn Steinbrink @ 2009-12-08 19:13 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: git, Junio C Hamano

On 2009.12.08 18:49:04 +0200, Michael S. Tsirkin wrote:
> On Tue, Dec 08, 2009 at 05:41:13PM +0100, Björn Steinbrink wrote:
> > > > Also, AFAICT this needs to be called like this:
> > > > git rebase --revisions foo..bar HEAD
> > > > 
> > > > Changing the meaning of the <upstream> argument and relying on the fact
> > > > that <newbase> defaults to <upstream>. If such a thing gets added, it
> > > > should rather work like --root, not using <upstream> at all, but --onto
> > > > <newbase> only. Maybe defaulting to HEAD for <newbase> and making --onto
> > > > optional, as it's reversed WRT what it does compared to the usual
> > > > rebase.
> > > 
> > > Sorry, I had trouble parsing the above.  Could you suggest e.g. how the
> > > help line should look?
> > 
> > Current:
> > git rebase [-i | --interactive] [options] [--onto <newbase>]
> > 	<upstream> [<branch>]
> > git rebase [-i | --interactive] [options] --onto <newbase>
> > 	--root [<branch>]
> > 
> > Add:
> > git rebase [-i | --interactive] [options] --revisions <range> [<branch>]
> > 
> > (Thinking about it, I guess an explicit --onto makes no sense with the
> > --revisions flag)
> 
> I agree.
> So this is different from what I implemented basically only in that
> we should disallow combining --onto with --revisions. Right?

It also drops <upstream>, because that makes no sense with --revisions.
So the only mandatory argument is the revision range.

Björn

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-08 19:11         ` Björn Steinbrink
@ 2009-12-08 20:00           ` Michael S. Tsirkin
  2009-12-09 13:19             ` Björn Steinbrink
  0 siblings, 1 reply; 43+ messages in thread
From: Michael S. Tsirkin @ 2009-12-08 20:00 UTC (permalink / raw)
  To: Björn Steinbrink; +Cc: git, Junio C Hamano

On Tue, Dec 08, 2009 at 08:11:07PM +0100, Björn Steinbrink wrote:
> On 2009.12.08 18:44:49 +0200, Michael S. Tsirkin wrote:
> > On Tue, Dec 08, 2009 at 05:37:37PM +0100, Björn Steinbrink wrote:
> > > On 2009.12.08 18:14:07 +0200, Michael S. Tsirkin wrote:
> > > > On Tue, Dec 08, 2009 at 05:08:22PM +0100, Björn Steinbrink wrote:
> > > > > On 2009.12.08 16:47:42 +0200, Michael S. Tsirkin wrote:
> > > > > > Add --revisions flag to rebase, so that it can be used
> > > > > > to apply an arbitrary range of commits on top
> > > > > > of a current branch.
> > > > > > 
> > > > > > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > > > > > ---
> > > > > > 
> > > > > > I've been wishing for this functionality for a while now,
> > > > > > so here goes. This isn't yet properly documented and I didn't
> > > > > > write a test, but the patch seems to work fine for me.
> > > > > > Any early flames/feedback?
> > > > > 
> > > > > This pretty much reverses what rebase normally does. Instead of "rebase
> > > > > this onto that" it's "'rebase' that onto this". And instead of updating
> > > > > the branch head that got rebased, the, uhm, "upstream" gets updated.
> > > > 
> > > > The last sentence is wrong I think - it is still the branch head that
> > > > is updated.
> > > 
> > > But you don't rebase the branch head. Before the rebase, the branch head
> > > doesn't reference the commits that get rebased. For example:
> > > 
> > > git checkout bar
> > > git rebase --revisions foo bar
> > > 
> > > You "rebase" the commits in foo's history, but you update bar.
> > 
> > Yes, that's the who point of the patch.
> 
> Yes, and it's "backwards" compared to the existing "rebase" modes, but
> more like "cherry-pick".
> 
> > The above applies a single commit, foo, on top of current branch bar.
> 
> Hm, no. I expected it to turn all commits reachable from foo into
> patches and applying them to bar. But actually, that should hit the
> special <since> mode of format-patch. So
> git rebase --revisions foo bar
> is (with your patch) actually the same as
> git rebase foo bar
> 
> So actually the example should have been:
> git rebase --root --revisions foo bar
> 
> Both invocations probably mess up the diff-stat as that becomes:
> git diff --stat --summary foo
> So it creates a diffstat of the diff from the working tree to "foo",
> which can't be right.
> 
> > 
> > > WRT the result, the above command should be equivalent to:
> > > git checkout bar
> > > git reset --hard foo
> > > git rebase --root --onto ORIG_HEAD;
> > > 
> > > And here, the commits currently reachable through "bar" are rebased, and
> > > "bar" also gets updated.
> > 
> > So this 
> > 1. won't be very useful, as you show it is easy
> >    to achieve with existing commands.
> 
> One can "almost" achieve it.
> git rebase --revision A..B foo
> 
> is about the same as:
> git checkout foo
> git reset --hard B
> git rebase --onto ORIG_HEAD A
> 
> But:
> a) The "reset --hard" obviously lacks the safety checks for clean
> index/working tree.
> b) "git rebase --abort" won't take you back to your initial state, but
> to B.
> c) It's not really obvious that you can do it and how to do it.
> 
> Another possibility would be:
> 
> git checkout B^0 # detach HEAD at B
> git rebase foo # rebase onto foo
> git checkout foo 
> git merge HEAD@{1} # Fast-forwards foo to the rebased stuff
> 
> That fixes a), avoid b) [because you don't mess up any branch head
> early] but is still subject to c).
> 
> And for both methods, the ORIG_HEAD and HEAD@{1} arguments are somewhat
> "unstable", e.g. checking out the wrong branch head first, and only then
> the correct one, you'd have to use HEAD@{2} instead of HEAD@{1} (because
> the reflog for HEAD got a new entry).
> 
> So you can already do what you want to do, but wrapping it in a single
> porcelain might still be useful because it's obviously a  lot easier and
> safer that way. That said, I wonder what kind of workflow you're using
> though, and why you require that feature. I've never needed something
> like that.

I need this often for many reasons:
-	Imagine developing a patchset with a complex bugfix on master branch.
	Then I decide to also apply (backport) this patchset to stable branch.
-	Imagine developing a bugfix/feature patchset on master branch.
	Then I decide the patchset is too large/unsafe and want to
	switch it to staging branch.
-	I have a large queue of patches on staging branch, I decide that
	a range of patches is mature enough for master.

And I often need -i to inspec/edit patches while doing this,
even though I can rebase -i later, but that would mean
figuring which commit to pass to rebase -i.

> > 2. interprets "foo" as branch name as opposed to
> >    revision range.
> 
> Well, a single committish is a "range" as far as the range-based
> commands are concerned, e.g. "git log master" treats "master" to mean
> all commits reachable it. If "rebase --revisions master" would do the
> same, that's at least consistent (and for single commit picks, there's
> already cherry-pick). The problem with your patch is that it passes the
> revision argument to format-patch as is, and:
> git format-patch foo
> is the same as
> git format-patch foo..HEAD
> 
> 
> > OTOH, rebase --revisions as I implemented is a "smarter cherry-pick"
> > which can't easily be achieved with existing commands, especially if
> > you add "-i".
> 
> And that "is a 'smarter cherry-pick'" is why I think that rebase is
> actually the wrong command to get that feature. While rebase internally
> does just mass-cherry-picking, it does that with commits in the current
> branch onto a specified branch. The --revisions flag makes it do things
> the other way around.
> 
> Björn

Well, implemenation-wise, teaching cherry-pick about multiple
commits seems very hard to me. We would need to teach it about
all the flags that rebase has to patch queue management.
So I can't implement it. Can you?

-- 
MST

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-08 14:47 [PATCH RFC] rebase: add --revisions flag Michael S. Tsirkin
  2009-12-08 16:08 ` Björn Steinbrink
@ 2009-12-08 20:22 ` Junio C Hamano
  2009-12-08 20:29   ` Sverre Rabbelier
                     ` (4 more replies)
  1 sibling, 5 replies; 43+ messages in thread
From: Junio C Hamano @ 2009-12-08 20:22 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: git

"Michael S. Tsirkin" <mst@redhat.com> writes:

> Add --revisions flag to rebase, so that it can be used
> to apply an arbitrary range of commits on top
> of a current branch.

Many people wanted to have "pick many commits onto the current HEAD" and I
think it would be a natural, uncontroversial and welcome addition to allow
"git cherry-pick A..B".  In fact, historically, people who wanted to have
"pick many commits" complained that the "rebase" interface was backwards,
because it works in the _wrong_ direction for _their_ usecase.  Of course,
when you _are_ rebasing a branch on top of some other branch, the way
"rebase" currently works is the _right_ direction.

But I think it is a reasonable thing to _implement_ the feature to
range-pick commits reusing the sequencing logic already in "rebase" and
"rebase -i".  That essentially is what we wanted to do with "git
sequencer" that would be a sequencing logic backend shared among rebase,
cherry-pick, and perhaps am.

So perhaps a good way to move forward is to teach "git cherry-pick A..B"
to be a thin wrapper that invokes a new hidden mode of operation added to
"rebase" that is not advertised to the end user.

I would suggest calling the option to invoke that hidden mode not
"--revisions", but "--reverse" or "--opposite" or something of that
nature, though.  It makes "rebase" work in different direction.

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-08 20:22 ` Junio C Hamano
@ 2009-12-08 20:29   ` Sverre Rabbelier
  2009-12-09  5:30     ` Christian Couder
  2009-12-09  8:47   ` Peter Krefting
                     ` (3 subsequent siblings)
  4 siblings, 1 reply; 43+ messages in thread
From: Sverre Rabbelier @ 2009-12-08 20:29 UTC (permalink / raw)
  To: Junio C Hamano, Stephan Beyer, Christian Couder, Daniel Barkalow; +Cc: Git List

Heya,

On Tue, Dec 8, 2009 at 21:22, Junio C Hamano <gitster@pobox.com> wrote:
> But I think it is a reasonable thing to _implement_ the feature to
> range-pick commits reusing the sequencing logic already in "rebase" and
> "rebase -i".  That essentially is what we wanted to do with "git
> sequencer" that would be a sequencing logic backend shared among rebase,
> cherry-pick, and perhaps am.

Speaking of which, what's the status of git sequencer? I seem to
remember some activity recently to slowly rewrite git rebase in c, but
I haven't seen anything since then. Is it still moving forward? Is
anyone interested in doing so? Just curious...

-- 
Cheers,

Sverre Rabbelier

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-08 16:44       ` Michael S. Tsirkin
  2009-12-08 19:11         ` Björn Steinbrink
@ 2009-12-09  4:51         ` Miles Bader
  1 sibling, 0 replies; 43+ messages in thread
From: Miles Bader @ 2009-12-09  4:51 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: Björn Steinbrink, git, Junio C Hamano

"Michael S. Tsirkin" <mst@redhat.com> writes:
> OTOH, rebase --revisions as I implemented is a "smarter cherry-pick" which
> can't easily be achieved with existing commands, especially if you add
> "-i".

It also allows making use of rebase's rather extensive machinery for
dealing with conflicts (e.g., rebase --continue / --skip / --abort).

But it would make more sense to have it in cherry-pick...
(cherry-pick --continue / --skip / --abort...)

-Miles

-- 
Consult, v.i. To seek another's disapproval of a course already decided on.

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-08 20:29   ` Sverre Rabbelier
@ 2009-12-09  5:30     ` Christian Couder
  2009-12-09  6:52       ` Christian Couder
  0 siblings, 1 reply; 43+ messages in thread
From: Christian Couder @ 2009-12-09  5:30 UTC (permalink / raw)
  To: Sverre Rabbelier
  Cc: Junio C Hamano, Stephan Beyer, Christian Couder, Daniel Barkalow,
	Git List, Johannes Schindelin

Hi,

On mardi 08 décembre 2009, Sverre Rabbelier wrote:
> Heya,
>
> On Tue, Dec 8, 2009 at 21:22, Junio C Hamano <gitster@pobox.com> wrote:
> > But I think it is a reasonable thing to _implement_ the feature to
> > range-pick commits reusing the sequencing logic already in "rebase" and
> > "rebase -i".  That essentially is what we wanted to do with "git
> > sequencer" that would be a sequencing logic backend shared among
> > rebase, cherry-pick, and perhaps am.
>
> Speaking of which, what's the status of git sequencer? I seem to
> remember some activity recently to slowly rewrite git rebase in c, but
> I haven't seen anything since then. Is it still moving forward? Is
> anyone interested in doing so? Just curious...

Last June and July, I sent some patch series to port "rebase -i" to C using 
code from the sequencer project. My goal was to save some interesting code 
from the sequencer GSoC 2008 project and at the same time to move 
forward "rebase -i" code toward a sequencer.

But Dscho and Junio didn't like the fact that the code from the sequencer I 
added was duplicating existing code and was not properly refactored, though 
it also added things that would be needed later for the sequencer. My plan 
was to refactor later, once I had a sequencer, but Junio and Dscho did not 
like that plan. They said it would be a too big maintenance burden.

So I agreed to not duplicate any existing code and to properly refactor 
everything. And I have been trying to take interesting and useful code from 
the sequencer project and to integrate it into existing commands. And this 
is why I sent yesterday the 4th version of my '"git reset --merge" related 
improvements' patch series.

Best regards,
Christian.

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-09  5:30     ` Christian Couder
@ 2009-12-09  6:52       ` Christian Couder
  2009-12-09  9:08         ` Sverre Rabbelier
  0 siblings, 1 reply; 43+ messages in thread
From: Christian Couder @ 2009-12-09  6:52 UTC (permalink / raw)
  To: Sverre Rabbelier
  Cc: Junio C Hamano, Stephan Beyer, Christian Couder, Daniel Barkalow,
	Git List, Johannes Schindelin

On mercredi 09 décembre 2009, Christian Couder wrote:
> Hi,
>
> On mardi 08 décembre 2009, Sverre Rabbelier wrote:
> > Heya,
> >
> > On Tue, Dec 8, 2009 at 21:22, Junio C Hamano <gitster@pobox.com> wrote:
> > > But I think it is a reasonable thing to _implement_ the feature to
> > > range-pick commits reusing the sequencing logic already in "rebase"
> > > and "rebase -i".  That essentially is what we wanted to do with "git
> > > sequencer" that would be a sequencing logic backend shared among
> > > rebase, cherry-pick, and perhaps am.
> >
> > Speaking of which, what's the status of git sequencer? I seem to
> > remember some activity recently to slowly rewrite git rebase in c, but
> > I haven't seen anything since then. Is it still moving forward? Is
> > anyone interested in doing so? Just curious...
>
> Last June and July, I sent some patch series to port "rebase -i" to C
> using code from the sequencer project. My goal was to save some
> interesting code from the sequencer GSoC 2008 project and at the same
> time to move forward "rebase -i" code toward a sequencer.
>
> But Dscho and Junio didn't like the fact that the code from the sequencer
> I added was duplicating existing code and was not properly refactored,
> though it also added things that would be needed later for the sequencer.
> My plan was to refactor later, once I had a sequencer, but Junio and
> Dscho did not like that plan. They said it would be a too big maintenance
> burden.
>
> So I agreed to not duplicate any existing code and to properly refactor
> everything. And I have been trying to take interesting and useful code
> from the sequencer project and to integrate it into existing commands.
> And this is why I sent yesterday the 4th version of my '"git reset
> --merge" related improvements' patch series.

After that I plan to work on cherry-pick and that could be useful to 
implement something like "git cherry-pick A..B".

See patch 11/15 from Stephan Beyer in my last "port rebase -i to C" series: 

http://thread.gmane.org/gmane.comp.version-control.git/127256/focus=127259

Regards,
Christian.

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-08 20:22 ` Junio C Hamano
  2009-12-08 20:29   ` Sverre Rabbelier
@ 2009-12-09  8:47   ` Peter Krefting
  2009-12-09  9:37     ` Michael S. Tsirkin
  2009-12-09 10:38   ` Michael S. Tsirkin
                     ` (2 subsequent siblings)
  4 siblings, 1 reply; 43+ messages in thread
From: Peter Krefting @ 2009-12-09  8:47 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Michael S. Tsirkin, Git Mailing List

Junio C Hamano:

> Many people wanted to have "pick many commits onto the current HEAD" and I 
> think it would be a natural, uncontroversial and welcome addition to allow 
> "git cherry-pick A..B".

Or even "git cherry-pick branch", as I naïvely tried doing before I 
understood what it did. This is definitely a feature that would help me.

The question of where it goes is actually a bit difficult, it is the same 
mode of operation as "git rebase", only the other way around. It is the same 
as "git cherry-pick", but called multiple times. And it is the same as "git 
merge --squash", but without squashing the commits into one.

So does this new mode go into rebase, cherry-pick or merge, or into all 
three? No matter which, proper documentation is needed.


Maybe this could also be used to implement a "git merge --squash A..B", a.k.a 
a "partial merge". (And if it could be implemented to allow a "git merge A..B" 
and later do a "git merge B" to merge the rest of the side-branch, that 
would be interesting).

-- 
\\// Peter - http://www.softwolves.pp.se/

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-09  6:52       ` Christian Couder
@ 2009-12-09  9:08         ` Sverre Rabbelier
  0 siblings, 0 replies; 43+ messages in thread
From: Sverre Rabbelier @ 2009-12-09  9:08 UTC (permalink / raw)
  To: Christian Couder
  Cc: Junio C Hamano, Stephan Beyer, Christian Couder, Daniel Barkalow,
	Git List, Johannes Schindelin

Heya,

On Wed, Dec 9, 2009 at 07:52, Christian Couder <chriscool@tuxfamily.org> wrote:

<snip>

> After that I plan to work on cherry-pick and that could be useful to
> implement something like "git cherry-pick A..B".

Ah, okay, thanks for the update!

-- 
Cheers,

Sverre Rabbelier

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-09  8:47   ` Peter Krefting
@ 2009-12-09  9:37     ` Michael S. Tsirkin
  2009-12-09 10:52       ` Peter Krefting
  0 siblings, 1 reply; 43+ messages in thread
From: Michael S. Tsirkin @ 2009-12-09  9:37 UTC (permalink / raw)
  To: Peter Krefting; +Cc: Junio C Hamano, Git Mailing List

On Wed, Dec 09, 2009 at 09:47:56AM +0100, Peter Krefting wrote:
> Junio C Hamano:
>
>> Many people wanted to have "pick many commits onto the current HEAD" 
>> and I think it would be a natural, uncontroversial and welcome addition 
>> to allow "git cherry-pick A..B".
>
> Or even "git cherry-pick branch", as I naïvely tried doing before I  
> understood what it did. This is definitely a feature that would help me.
>
> The question of where it goes is actually a bit difficult, it is the same 
> mode of operation as "git rebase", only the other way around. It is the 
> same as "git cherry-pick", but called multiple times. And it is the same 
> as "git merge --squash", but without squashing the commits into one.
>
> So does this new mode go into rebase, cherry-pick or merge, or into all  
> three? No matter which, proper documentation is needed.
>
>
> Maybe this could also be used to implement a "git merge --squash A..B", 
> a.k.a a "partial merge".

What exactly should it do?

> (And if it could be implemented to allow a "git 
> merge A..B" and later do a "git merge B" to merge the rest of the 
> side-branch, that would be interesting).

rebase already tries to detect previously applied commits.
Maybe we can teach it to use more heuristics.

> -- 
> \\// Peter - http://www.softwolves.pp.se/

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-08 20:22 ` Junio C Hamano
  2009-12-08 20:29   ` Sverre Rabbelier
  2009-12-09  8:47   ` Peter Krefting
@ 2009-12-09 10:38   ` Michael S. Tsirkin
  2009-12-09 10:55     ` Matthieu Moy
  2009-12-09 13:30   ` Matthieu Moy
  2009-12-13 22:47   ` David Kågedal
  4 siblings, 1 reply; 43+ messages in thread
From: Michael S. Tsirkin @ 2009-12-09 10:38 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On Tue, Dec 08, 2009 at 12:22:59PM -0800, Junio C Hamano wrote:
> "Michael S. Tsirkin" <mst@redhat.com> writes:
> 
> > Add --revisions flag to rebase, so that it can be used
> > to apply an arbitrary range of commits on top
> > of a current branch.
> 
> Many people wanted to have "pick many commits onto the current HEAD" and I
> think it would be a natural, uncontroversial and welcome addition to allow
> "git cherry-pick A..B".  In fact, historically, people who wanted to have
> "pick many commits" complained that the "rebase" interface was backwards,
> because it works in the _wrong_ direction for _their_ usecase.  Of course,
> when you _are_ rebasing a branch on top of some other branch, the way
> "rebase" currently works is the _right_ direction.
> 
> But I think it is a reasonable thing to _implement_ the feature to
> range-pick commits reusing the sequencing logic already in "rebase" and
> "rebase -i".  That essentially is what we wanted to do with "git
> sequencer" that would be a sequencing logic backend shared among rebase,
> cherry-pick, and perhaps am.
> 
> So perhaps a good way to move forward is to teach "git cherry-pick A..B"
> to be a thin wrapper that invokes a new hidden mode of operation added to
> "rebase" that is not advertised to the end user.
> 
> I would suggest calling the option to invoke that hidden mode not
> "--revisions", but "--reverse" or "--opposite" or something of that
> nature, though.  It makes "rebase" work in different direction.

cherry-pick is a binary though while rebase is a shell script.
Should I just exec git rebase? git-rebase?

-- 
MST

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-09  9:37     ` Michael S. Tsirkin
@ 2009-12-09 10:52       ` Peter Krefting
  2009-12-09 11:22         ` Björn Steinbrink
  0 siblings, 1 reply; 43+ messages in thread
From: Peter Krefting @ 2009-12-09 10:52 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: Junio C Hamano, Git Mailing List

Michael S. Tsirkin:

>> Maybe this could also be used to implement a "git merge --squash A..B", 
>> a.k.a a "partial merge".
> What exactly should it do?

The same thing, apply a set of changes on top of the current branch, just 
using the "merge" name, and not "rebase" or "cherry-pick". "merge --squash" 
is just "cherry-pick" with a different name.

-- 
\\// Peter - http://www.softwolves.pp.se/

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-09 10:38   ` Michael S. Tsirkin
@ 2009-12-09 10:55     ` Matthieu Moy
  0 siblings, 0 replies; 43+ messages in thread
From: Matthieu Moy @ 2009-12-09 10:55 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: Junio C Hamano, git

"Michael S. Tsirkin" <mst@redhat.com> writes:

> cherry-pick is a binary though while rebase is a shell script.
> Should I just exec git rebase? git-rebase?

See run-command.h :

#define RUN_GIT_CMD	     2	/*If this is to be git sub-command */
int run_command_v_opt(const char **argv, int opt);

That should do the trick (grep 'run_command_v_opt.*GIT_CMD' *.c for
some example of uses).

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-09 10:52       ` Peter Krefting
@ 2009-12-09 11:22         ` Björn Steinbrink
  2009-12-09 11:48           ` Andreas Schwab
  2009-12-09 13:20           ` Peter Krefting
  0 siblings, 2 replies; 43+ messages in thread
From: Björn Steinbrink @ 2009-12-09 11:22 UTC (permalink / raw)
  To: Peter Krefting; +Cc: Michael S. Tsirkin, Junio C Hamano, Git Mailing List

On 2009.12.09 11:52:41 +0100, Peter Krefting wrote:
> Michael S. Tsirkin:
> 
> >>Maybe this could also be used to implement a "git merge --squash
> >>A..B", a.k.a a "partial merge".
> >What exactly should it do?
> 
> The same thing, apply a set of changes on top of the current branch,
> just using the "merge" name, and not "rebase" or "cherry-pick".
> "merge --squash" is just "cherry-pick" with a different name.

Err, no. "git merge --squash foo" merges all changes from the merge base
of HEAD and foo up to foo. "git cherry-pick foo" takes just the changes
from foo^ to foo. For example:

A---B---C (master)
 \
  D---E---F (foo)

git cherry-pick foo # Tries to create a new commit with the changes from
                    # "git diff D F"

git merge --squash foo # Tries to create a new commit with the changes
                       # from "git diff A F"

Björn

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-09 11:22         ` Björn Steinbrink
@ 2009-12-09 11:48           ` Andreas Schwab
  2009-12-09 12:06             ` Björn Steinbrink
  2009-12-09 13:20           ` Peter Krefting
  1 sibling, 1 reply; 43+ messages in thread
From: Andreas Schwab @ 2009-12-09 11:48 UTC (permalink / raw)
  To: Björn Steinbrink
  Cc: Peter Krefting, Michael S. Tsirkin, Junio C Hamano, Git Mailing List

Björn Steinbrink <B.Steinbrink@gmx.de> writes:

> Err, no. "git merge --squash foo" merges all changes from the merge base
> of HEAD and foo up to foo. "git cherry-pick foo" takes just the changes
> from foo^ to foo. For example:
>
> A---B---C (master)
>  \
>   D---E---F (foo)
>
> git cherry-pick foo # Tries to create a new commit with the changes from
>                     # "git diff D F"

Did you mean "git diff E F"?

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-09 11:48           ` Andreas Schwab
@ 2009-12-09 12:06             ` Björn Steinbrink
  2009-12-09 12:07               ` Michael S. Tsirkin
  0 siblings, 1 reply; 43+ messages in thread
From: Björn Steinbrink @ 2009-12-09 12:06 UTC (permalink / raw)
  To: Andreas Schwab
  Cc: Peter Krefting, Michael S. Tsirkin, Junio C Hamano, Git Mailing List

On 2009.12.09 12:48:24 +0100, Andreas Schwab wrote:
> Björn Steinbrink <B.Steinbrink@gmx.de> writes:
> 
> > Err, no. "git merge --squash foo" merges all changes from the merge base
> > of HEAD and foo up to foo. "git cherry-pick foo" takes just the changes
> > from foo^ to foo. For example:
> >
> > A---B---C (master)
> >  \
> >   D---E---F (foo)
> >
> > git cherry-pick foo # Tries to create a new commit with the changes from
> >                     # "git diff D F"
> 
> Did you mean "git diff E F"?

Ugh, yes, of course. Thanks.

Björn

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-09 12:06             ` Björn Steinbrink
@ 2009-12-09 12:07               ` Michael S. Tsirkin
  2009-12-09 13:06                 ` Björn Steinbrink
  0 siblings, 1 reply; 43+ messages in thread
From: Michael S. Tsirkin @ 2009-12-09 12:07 UTC (permalink / raw)
  To: Björn Steinbrink
  Cc: Andreas Schwab, Peter Krefting, Junio C Hamano, Git Mailing List

On Wed, Dec 09, 2009 at 01:06:10PM +0100, Björn Steinbrink wrote:
> On 2009.12.09 12:48:24 +0100, Andreas Schwab wrote:
> > Björn Steinbrink <B.Steinbrink@gmx.de> writes:
> > 
> > > Err, no. "git merge --squash foo" merges all changes from the merge base
> > > of HEAD and foo up to foo. "git cherry-pick foo" takes just the changes
> > > from foo^ to foo. For example:
> > >
> > > A---B---C (master)
> > >  \
> > >   D---E---F (foo)
> > >
> > > git cherry-pick foo # Tries to create a new commit with the changes from
> > >                     # "git diff D F"
> > 
> > Did you mean "git diff E F"?
> 
> Ugh, yes, of course. Thanks.
> 
> Björn

So this will be best written as
git cherry-pick ..foo

-- 
MST

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-09 12:07               ` Michael S. Tsirkin
@ 2009-12-09 13:06                 ` Björn Steinbrink
  2009-12-09 19:46                   ` Junio C Hamano
  0 siblings, 1 reply; 43+ messages in thread
From: Björn Steinbrink @ 2009-12-09 13:06 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Andreas Schwab, Peter Krefting, Junio C Hamano, Git Mailing List

On 2009.12.09 14:07:48 +0200, Michael S. Tsirkin wrote:
> On Wed, Dec 09, 2009 at 01:06:10PM +0100, Björn Steinbrink wrote:
> > On 2009.12.09 12:48:24 +0100, Andreas Schwab wrote:
> > > Björn Steinbrink <B.Steinbrink@gmx.de> writes:
> > > 
> > > > Err, no. "git merge --squash foo" merges all changes from the merge base
> > > > of HEAD and foo up to foo. "git cherry-pick foo" takes just the changes
> > > > from foo^ to foo. For example:
> > > >
> > > > A---B---C (master)
> > > >  \
> > > >   D---E---F (foo)
> > > >
> > > > git cherry-pick foo # Tries to create a new commit with the changes from
> > > >                     # "git diff D F"
> > > 
> > > Did you mean "git diff E F"?
> > 
> > Ugh, yes, of course. Thanks.
> 
> So this will be best written as
> git cherry-pick ..foo

No, "git cherry-pick ..foo" should pick the individual commits, and not
create a single big commit like "git merge --squash". So such a command
should make you end up with:

A---B---C---D'--E'--F' (master)
         \
          D---E---F

Not:
A---B---C---M (master)
         \
          D---E---F (foo)

[M being the "sqash-merge"]

"merge --squash" is one of the things I really dislike, because it turns
off the "history" part of the merge. You can say "Merging in git is about
histories, merging in svn is about changes only" to describe the major
difference for the merge commands in the two systems... "But then
there's --squash which turns git into svn".

I think a "cherry-pick --squash <range>" command would be nicer from a
conceptual point of view, but it's way too late for merge --squash to be
dropped. And I guess it wouldn't be trivial to add such a flag, and not
worth the effort, as you could as well use the interactive mode and
replace "pick" with "squash" manually. (An el cheapo implementation that
automatically replaces it would likely confuse the user, because he
asked for a single commit, but might get to fix conflicts for all the
individual commits).

Björn

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-08 20:00           ` Michael S. Tsirkin
@ 2009-12-09 13:19             ` Björn Steinbrink
  2009-12-09 14:02               ` Michael S. Tsirkin
  0 siblings, 1 reply; 43+ messages in thread
From: Björn Steinbrink @ 2009-12-09 13:19 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: git, Junio C Hamano

On 2009.12.08 22:00:17 +0200, Michael S. Tsirkin wrote:
> On Tue, Dec 08, 2009 at 08:11:07PM +0100, Björn Steinbrink wrote:
> > So you can already do what you want to do, but wrapping it in a single
> > porcelain might still be useful because it's obviously a  lot easier and
> > safer that way. That said, I wonder what kind of workflow you're using
> > though, and why you require that feature. I've never needed something
> > like that.
> 
> I need this often for many reasons:
> -	Imagine developing a patchset with a complex bugfix on master branch.
> 	Then I decide to also apply (backport) this patchset to stable branch.

Hm, I'd also imagine that you want a separate branch then, and not
directly mess up the stable branch, so I'd do:
git branch foo-stable foo # Create a branch for the backport
git rebase --onto stable master foo-stable # Backport

Now you got your backported version and can merge it to "stable".

Common wisdom is do things the other way around though. Create the
bugfix for the oldest branch that it applies to, then merge it forward,
either doing:

"bugfix -> stable" and "stable -> master" merges, or
"bugfix -> stable" and "bugfix -> master" merges.

That approach has the advantage that you don't get multiple commits
doing the same thing, which you get with rebasing/cherry-picking.

IIRC the gitworkflows manpage describe that in some more detail.

> -	Imagine developing a bugfix/feature patchset on master branch.
> 	Then I decide the patchset is too large/unsafe and want to
> 	switch it to staging branch.

Hm, so you have a topic branch "foo" based upon master, but it's too
experimental so you don't want to merge it to master, but "staging". I
don't see why you even have to rebase it then. "staging" is likely ahead
of master, so the merge base of "foo" and "master" is also reachable
through "staging", and simply merging "foo" to "staging" should work
without any ill-effects.

> -	I have a large queue of patches on staging branch, I decide that
> 	a range of patches is mature enough for master.

Basically, same deal as with the first two cases. If the series is
directly on "staging" (i.e. you didn't create a topic branch), you can
create one now:
git branch foo $last_commit_for_foo
git rebase --onto master $first_commit_for_foo^ foo

And you got your backported topic branch for "foo".

Or you already have a topic branch "foo-staging", but it's based upon
some commit only in "staging" but not in "master", so a plain merge
would mess things up. Same deal as with backporting from "master" to
"stable"

And in this case it's also true that basing the topic branches on
"master" instead of "staging" makes things easier. That way, you can
merge to either "staging" or "master" without any ill-effects.

Björn

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-09 11:22         ` Björn Steinbrink
  2009-12-09 11:48           ` Andreas Schwab
@ 2009-12-09 13:20           ` Peter Krefting
  2009-12-09 13:41             ` Björn Steinbrink
  1 sibling, 1 reply; 43+ messages in thread
From: Peter Krefting @ 2009-12-09 13:20 UTC (permalink / raw)
  To: Björn Steinbrink
  Cc: Michael S. Tsirkin, Junio C Hamano, Git Mailing List

Björn Steinbrink:

> Err, no. "git merge --squash foo" merges all changes from the merge base 
> of HEAD and foo up to foo. "git cherry-pick foo" takes just the changes
>  from foo^ to foo.

Exactly!

What I meant to say in the original message was that conceptually, the 
difference between a "git rebase --reverse A..B", a "git cherry-pick A..B" 
and a "git merge --squash A..B" is minute.

And when continuing the thought experiment, the step from "git merge 
--squash A..B" to "git merge A..B" is not very large either, just (a 
lot) more difficult to implement.

-- 
\\// Peter - http://www.softwolves.pp.se/

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-08 20:22 ` Junio C Hamano
                     ` (2 preceding siblings ...)
  2009-12-09 10:38   ` Michael S. Tsirkin
@ 2009-12-09 13:30   ` Matthieu Moy
  2009-12-09 13:45     ` Michael S. Tsirkin
  2009-12-09 20:10     ` Junio C Hamano
  2009-12-13 22:47   ` David Kågedal
  4 siblings, 2 replies; 43+ messages in thread
From: Matthieu Moy @ 2009-12-09 13:30 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Michael S. Tsirkin, git

Junio C Hamano <gitster@pobox.com> writes:

> So perhaps a good way to move forward is to teach "git cherry-pick A..B"
> to be a thin wrapper that invokes a new hidden mode of operation added to
> "rebase" that is not advertised to the end user.
>
> I would suggest calling the option to invoke that hidden mode not
> "--revisions", but "--reverse" or "--opposite" or something of that
> nature, though.  It makes "rebase" work in different direction.

Intuitively,

  git rebase --reverse A..B

would mean "take the range A..B, and start applying the patches from
B, going in reverse order up to A", like "git log --reverse". So, I'd
find it misleading.

Perhaps "git rebase --cherry-pick A..B" would be a better name. No
objection for --opposite either.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-09 13:20           ` Peter Krefting
@ 2009-12-09 13:41             ` Björn Steinbrink
  2009-12-10  8:43               ` Peter Krefting
  0 siblings, 1 reply; 43+ messages in thread
From: Björn Steinbrink @ 2009-12-09 13:41 UTC (permalink / raw)
  To: Peter Krefting; +Cc: Michael S. Tsirkin, Junio C Hamano, Git Mailing List

On 2009.12.09 14:20:23 +0100, Peter Krefting wrote:
> Björn Steinbrink:
> 
> >Err, no. "git merge --squash foo" merges all changes from the
> >merge base of HEAD and foo up to foo. "git cherry-pick foo" takes
> >just the changes
> > from foo^ to foo.
> 
> Exactly!
> 
> What I meant to say in the original message was that conceptually,
> the difference between a "git rebase --reverse A..B", a "git
> cherry-pick A..B" and a "git merge --squash A..B" is minute.
> 
> And when continuing the thought experiment, the step from "git merge
> --squash A..B" to "git merge A..B" is not very large either, just (a
> lot) more difficult to implement.

"git merge" is about merging histories. --squash and the A..B you
suggest make it degenerate into merging changes (and you can't record
that using the commit DAG). So that messes things up conceptually.

Implementing probably wouldn't be that hard, IIRC it should be a matter
of messing with the fake merge base that cherry-pick uses to get its job
done. While "git cherry-pick foo" uses foo^ as the merge base, you'd
just make "git merge --squash A..B" work like "git cherry-pick B" but
use A as the fake merge base. It's been a while since I looked at the
cherry-pick code though, so I might be off here.

(Kind of ironic though that I didn't think of that when I said that
"cherry-pick --squash" would be hard to do...)

Anyway, "git merge" with a range simply makes no sense at all given how
git's merge works (opposed to svn's idea of merging, which is about
changes, not about histories). If you want a squash flag, tell
cherry-pick to handle ranges and teach such a flag to it.

Björn

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-09 13:30   ` Matthieu Moy
@ 2009-12-09 13:45     ` Michael S. Tsirkin
  2009-12-09 14:01       ` Björn Steinbrink
  2009-12-09 20:10     ` Junio C Hamano
  1 sibling, 1 reply; 43+ messages in thread
From: Michael S. Tsirkin @ 2009-12-09 13:45 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: Junio C Hamano, git

On Wed, Dec 09, 2009 at 02:30:06PM +0100, Matthieu Moy wrote:
> Junio C Hamano <gitster@pobox.com> writes:
> 
> > So perhaps a good way to move forward is to teach "git cherry-pick A..B"
> > to be a thin wrapper that invokes a new hidden mode of operation added to
> > "rebase" that is not advertised to the end user.
> >
> > I would suggest calling the option to invoke that hidden mode not
> > "--revisions", but "--reverse" or "--opposite" or something of that
> > nature, though.  It makes "rebase" work in different direction.
> 
> Intuitively,
> 
>   git rebase --reverse A..B
> 
> would mean "take the range A..B, and start applying the patches from
> B, going in reverse order up to A", like "git log --reverse". So, I'd
> find it misleading.
> 
> Perhaps "git rebase --cherry-pick A..B" would be a better name. No
> objection for --opposite either.

I relly like --cherry-pick. Junio, objections to that one?

> -- 
> Matthieu Moy
> http://www-verimag.imag.fr/~moy/

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-09 13:45     ` Michael S. Tsirkin
@ 2009-12-09 14:01       ` Björn Steinbrink
  2009-12-09 14:12         ` Michael S. Tsirkin
  0 siblings, 1 reply; 43+ messages in thread
From: Björn Steinbrink @ 2009-12-09 14:01 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: Matthieu Moy, Junio C Hamano, git

On 2009.12.09 15:45:36 +0200, Michael S. Tsirkin wrote:
> On Wed, Dec 09, 2009 at 02:30:06PM +0100, Matthieu Moy wrote:
> > Junio C Hamano <gitster@pobox.com> writes:
> > 
> > > So perhaps a good way to move forward is to teach "git cherry-pick A..B"
> > > to be a thin wrapper that invokes a new hidden mode of operation added to
> > > "rebase" that is not advertised to the end user.
> > >
> > > I would suggest calling the option to invoke that hidden mode not
> > > "--revisions", but "--reverse" or "--opposite" or something of that
> > > nature, though.  It makes "rebase" work in different direction.
> > 
> > Intuitively,
> > 
> >   git rebase --reverse A..B
> > 
> > would mean "take the range A..B, and start applying the patches from
> > B, going in reverse order up to A", like "git log --reverse". So, I'd
> > find it misleading.
> > 
> > Perhaps "git rebase --cherry-pick A..B" would be a better name. No
> > objection for --opposite either.
> 
> I relly like --cherry-pick. Junio, objections to that one?

Hm, there's also (the probably not so well known)
"git rev-list --cherry-pick A...B", which excludes commits that appear
on both A and B and have the same patch id. I'd rather call the rev-list
option a misnomer than the suggested hidden option for rebase, but I'd
call it --cherry-pick-mode or --cherry-picking (like am's hidden "git am
--rebasing"), just to make sure... Of course, it's not _that_ important,
as it's going to be a hidden option, so user confusion is probably not
that much of a concern.

Björn

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-09 13:19             ` Björn Steinbrink
@ 2009-12-09 14:02               ` Michael S. Tsirkin
  0 siblings, 0 replies; 43+ messages in thread
From: Michael S. Tsirkin @ 2009-12-09 14:02 UTC (permalink / raw)
  To: Björn Steinbrink; +Cc: git, Junio C Hamano

On Wed, Dec 09, 2009 at 02:19:45PM +0100, Björn Steinbrink wrote:
> On 2009.12.08 22:00:17 +0200, Michael S. Tsirkin wrote:
> > On Tue, Dec 08, 2009 at 08:11:07PM +0100, Björn Steinbrink wrote:
> > > So you can already do what you want to do, but wrapping it in a single
> > > porcelain might still be useful because it's obviously a  lot easier and
> > > safer that way. That said, I wonder what kind of workflow you're using
> > > though, and why you require that feature. I've never needed something
> > > like that.
> > 
> > I need this often for many reasons:
> > -	Imagine developing a patchset with a complex bugfix on master branch.
> > 	Then I decide to also apply (backport) this patchset to stable branch.
> 
> Hm, I'd also imagine that you want a separate branch then, and not
> directly mess up the stable branch,

Well, directly working with a stable branch is easier, so yes,
I want to mess it up: this is just my local tree, if anything
goes wrong  I just don't push or "reset --hard origin/stable".

> so I'd do:
> git branch foo-stable foo # Create a branch for the backport
> git rebase --onto stable master foo-stable # Backport
> 
> Now you got your backported version and can merge it to "stable".

The annoying thing is that merge step. I can create a merge
commit if I mistype things, and I do not want any
merge commits, I want to create linear history.

> Common wisdom is do things the other way around though. Create the
> bugfix for the oldest branch that it applies to, then merge it forward,
> either doing:
> 
> "bugfix -> stable" and "stable -> master" merges, or
> "bugfix -> stable" and "bugfix -> master" merges.
> 
> That approach has the advantage that you don't get multiple commits
> doing the same thing, which you get with rebasing/cherry-picking.
> 
> IIRC the gitworkflows manpage describe that in some more detail.


I know. The advantage of making all changes to master first
is that this way a change gets more review and testing before
being applied to stable. Further, often different people
maintain master and stable branches.

> > -	Imagine developing a bugfix/feature patchset on master branch.
> > 	Then I decide the patchset is too large/unsafe and want to
> > 	switch it to staging branch.
> 
> Hm, so you have a topic branch "foo" based upon master, but it's too
> experimental so you don't want to merge it to master, but "staging". I
> don't see why you even have to rebase it then. "staging" is likely ahead
> of master, so the merge base of "foo" and "master" is also reachable
> through "staging", and simply merging "foo" to "staging" should work
> without any ill-effects.

Yes but I want my development history to be linear,
so that format patch rebase -i etc work well.

> > -	I have a large queue of patches on staging branch, I decide that
> > 	a range of patches is mature enough for master.
> 
> Basically, same deal as with the first two cases. If the series is
> directly on "staging" (i.e. you didn't create a topic branch), you can
> create one now:
> git branch foo $last_commit_for_foo
> git rebase --onto master $first_commit_for_foo^ foo
> 
> And you got your backported topic branch for "foo".
> 
> Or you already have a topic branch "foo-staging", but it's based upon
> some commit only in "staging" but not in "master", so a plain merge
> would mess things up. Same deal as with backporting from "master" to
> "stable"

Yes, I understand that creating a temporary branch and checking it out
then merging it will make rebase do what I want.
The only disadvantage is that I need to remember where I am in the
process, while an "atomic" command does this for me.

> And in this case it's also true that basing the topic branches on
> "master" instead of "staging" makes things easier. That way, you can
> merge to either "staging" or "master" without any ill-effects.
> 
> Björn

As above, I do not want merges.

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-09 14:01       ` Björn Steinbrink
@ 2009-12-09 14:12         ` Michael S. Tsirkin
  0 siblings, 0 replies; 43+ messages in thread
From: Michael S. Tsirkin @ 2009-12-09 14:12 UTC (permalink / raw)
  To: Björn Steinbrink; +Cc: Matthieu Moy, Junio C Hamano, git

On Wed, Dec 09, 2009 at 03:01:45PM +0100, Björn Steinbrink wrote:
> On 2009.12.09 15:45:36 +0200, Michael S. Tsirkin wrote:
> > On Wed, Dec 09, 2009 at 02:30:06PM +0100, Matthieu Moy wrote:
> > > Junio C Hamano <gitster@pobox.com> writes:
> > > 
> > > > So perhaps a good way to move forward is to teach "git cherry-pick A..B"
> > > > to be a thin wrapper that invokes a new hidden mode of operation added to
> > > > "rebase" that is not advertised to the end user.
> > > >
> > > > I would suggest calling the option to invoke that hidden mode not
> > > > "--revisions", but "--reverse" or "--opposite" or something of that
> > > > nature, though.  It makes "rebase" work in different direction.
> > > 
> > > Intuitively,
> > > 
> > >   git rebase --reverse A..B
> > > 
> > > would mean "take the range A..B, and start applying the patches from
> > > B, going in reverse order up to A", like "git log --reverse". So, I'd
> > > find it misleading.
> > > 
> > > Perhaps "git rebase --cherry-pick A..B" would be a better name. No
> > > objection for --opposite either.
> > 
> > I relly like --cherry-pick. Junio, objections to that one?
> 
> Hm, there's also (the probably not so well known)
> "git rev-list --cherry-pick A...B", which excludes commits that appear
> on both A and B and have the same patch id. I'd rather call the rev-list
> option a misnomer than the suggested hidden option for rebase, but I'd
> call it --cherry-pick-mode or --cherry-picking (like am's hidden "git am
> --rebasing"), just to make sure... Of course, it's not _that_ important,
> as it's going to be a hidden option, so user confusion is probably not
> that much of a concern.
> 
> Björn

OK, --cherry-picking looks fine as well.

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-09 13:06                 ` Björn Steinbrink
@ 2009-12-09 19:46                   ` Junio C Hamano
  2009-12-10  7:43                     ` Björn Steinbrink
  0 siblings, 1 reply; 43+ messages in thread
From: Junio C Hamano @ 2009-12-09 19:46 UTC (permalink / raw)
  To: Björn Steinbrink
  Cc: Michael S. Tsirkin, Andreas Schwab, Peter Krefting, Git Mailing List

Björn Steinbrink <B.Steinbrink@gmx.de> writes:

> "merge --squash" is one of the things I really dislike, because it turns
> off the "history" part of the merge. You can say "Merging in git is about
> histories, merging in svn is about changes only" to describe the major
> difference for the merge commands in the two systems... "But then
> there's --squash which turns git into svn".

I agree with this to some degree, but I do not offhand think of a better
alternative.  

At the first sight, it looks as if what "merge --squash" does was
implemented as a new option "--squash" to the "merge" command merely
because the way _how_ it internally needs to compute the result was
already available in the implementation of "merge" command, and not
necessarily because _what_ it does was conceptually consistent with the
way "merge" works.

But at the conceptual level, "merge --squash" is a short-hand for this
command sequence:

    git rebase -i HEAD that-branch
    ... make everything except the first one into "squash"
    git checkout - ;# come back to the original branch
    git merge that-branch ;# fast forward to it

So after all, it is "merge it after squashing them".

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-09 13:30   ` Matthieu Moy
  2009-12-09 13:45     ` Michael S. Tsirkin
@ 2009-12-09 20:10     ` Junio C Hamano
  1 sibling, 0 replies; 43+ messages in thread
From: Junio C Hamano @ 2009-12-09 20:10 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: Michael S. Tsirkin, git

Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:

> Perhaps "git rebase --cherry-pick A..B" would be a better name. No
> objection for --opposite either.

As somebody mentioned, "--cherry-picking", similar to "am --rebasing" that
is also an unadvertised internal implementation detail, is a good name.

In the very old days, the original "rebase" command was a command to
"set-up and run 'am -3' command in order to transplant the current branch
onto somewhere else."

That was obviously too long for a command name and description, and I
shorten it to "rebase", to name the command after what it is _for_ (not
"what it does", nor "how it does it").  Because the command was to "set up
and run am-3", it was natural at the conceptual level that the way to
continue after a failed/conflicted patch application was "am --resolved".

But since then, the concept of "rebasing" got established more firmly and
how "rebase" can be done has become much less relevant.  The original name
"rebase" stopped being short for "set up and run am-3 for rebasing", but
about what it _does_ (i.e. "it rebases").  And "rebase --continue" has
become a natural way to drive "am --continue" at that point, to accomodate
for the change in the end-user conception. These days, "set up and run
am-3 for rebasing" is not even _how_ it does the "rebase", as "rebase -i"
does not even use am-3.  So "rebase --continue" was a logical conclusion
of the command's evolution.

The lesson to be learned from this history is that "cherry-pick A..B" that
internally runs "rebase --cherry-picking" will need a similar "--continue"
support that delegates to "rebase".  "running am", which was originally
the whole point of "rebase", later became an implementation detail, and we
needed to teach "--continue" to "rebase" at that point.

Because from day one "running rebase -i" will be an implementation detail
of "cherry-pick A..B", we need to teach "cherry-pick" to pass "--abort",
"--continue", etc. to underlying "rebase" for the same reason.

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-09 19:46                   ` Junio C Hamano
@ 2009-12-10  7:43                     ` Björn Steinbrink
  2009-12-10 17:20                       ` Junio C Hamano
  0 siblings, 1 reply; 43+ messages in thread
From: Björn Steinbrink @ 2009-12-10  7:43 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Michael S. Tsirkin, Andreas Schwab, Peter Krefting, Git Mailing List

On 2009.12.09 11:46:01 -0800, Junio C Hamano wrote:
> Björn Steinbrink <B.Steinbrink@gmx.de> writes:
> 
> > "merge --squash" is one of the things I really dislike, because it turns
> > off the "history" part of the merge. You can say "Merging in git is about
> > histories, merging in svn is about changes only" to describe the major
> > difference for the merge commands in the two systems... "But then
> > there's --squash which turns git into svn".
> 
> I agree with this to some degree, but I do not offhand think of a better
> alternative.  
> 
> At the first sight, it looks as if what "merge --squash" does was
> implemented as a new option "--squash" to the "merge" command merely
> because the way _how_ it internally needs to compute the result was
> already available in the implementation of "merge" command, and not
> necessarily because _what_ it does was conceptually consistent with the
> way "merge" works.
> 
> But at the conceptual level, "merge --squash" is a short-hand for this
> command sequence:
> 
>     git rebase -i HEAD that-branch
>     ... make everything except the first one into "squash"
>     git checkout - ;# come back to the original branch
>     git merge that-branch ;# fast forward to it
> 
> So after all, it is "merge it after squashing them".

To me, that approach looks backwards, just like the "rebase --revisions"
proposal. "rebase" just happens to already provide the necessary
operations, but if cherry-pick would accepts ranges, this looks a lot
more logical to me:

git cherry-pick HEAD..that_branch
git reset --soft this_branch@{1} # [1]
git commit

[1] I assume that like "rebase", such a cherry-pick command would
already add a single reflog entry for the current branch

I cherry-pick all changes, and then use reset + commit to squash them
together to a single commit. To me, it's "I want to get all the changes
and squash them into a single commit", not "I want to squash the other
side's history in the background, without actually affecting the other
side and then merge that squashed version of the history".

So "cherry-pick --squash ..that_branch" seems more logical at the
conceptual level.  Internally, it could of course just do a three-way
merge, instead of being stupid and repeating the "apply, commit --amend"
sequence over and over again.

Björn

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-09 13:41             ` Björn Steinbrink
@ 2009-12-10  8:43               ` Peter Krefting
  2009-12-10 11:08                 ` Björn Steinbrink
  0 siblings, 1 reply; 43+ messages in thread
From: Peter Krefting @ 2009-12-10  8:43 UTC (permalink / raw)
  To: Björn Steinbrink
  Cc: Michael S. Tsirkin, Junio C Hamano, Git Mailing List

Björn Steinbrink:

> "git merge" is about merging histories. --squash and the A..B you suggest 
> make it degenerate into merging changes (and you can't record that using 
> the commit DAG). So that messes things up conceptually.

I know, this is the one "feature" of CVS that I sometimes miss in Git, that 
I cannot "merge" just parts of a history, and have that recorded in the 
history tree. I know it's wrong, I know I could do it better, but sometimes 
it's the shortcut that would make life easier for me. :-)

But the reason I mentioned it was because of the discussion on whether the 
"reverse rebase" should be an option to "cherry-pick" or not, and I 
mentioned that it could just as well be "merge" since it can be used to 
throw away history as well.

> Anyway, "git merge" with a range simply makes no sense at all given how 
> git's merge works (opposed to svn's idea of merging, which is about 
> changes, not about histories). If you want a squash flag, tell cherry-pick 
> to handle ranges and teach such a flag to it.

And tell "merge" to tell me that if I try, so that if I try

   $ git merge A..B

I would get a message saying something like

   Cannot merge a range of commits. Try "git cherry-pick A..B" or
   "git rebase --reverse A..B".

And perhaps we could also in the same way retire --squash?

   $ git merge --squash B
   The "--squash" option is obsolete. Please use "git cherry-pick
   --squash B".

(with a transition period where it would just call the other). Or whatever 
the options to simulate the old behaviour would be. This would make it 
clearer that "merge" preserves history while "cherry-pick" and "rebase" do 
not.

-- 
\\// Peter - http://www.softwolves.pp.se/

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-10  8:43               ` Peter Krefting
@ 2009-12-10 11:08                 ` Björn Steinbrink
  0 siblings, 0 replies; 43+ messages in thread
From: Björn Steinbrink @ 2009-12-10 11:08 UTC (permalink / raw)
  To: Peter Krefting; +Cc: Michael S. Tsirkin, Junio C Hamano, Git Mailing List

On 2009.12.10 09:43:51 +0100, Peter Krefting wrote:
> Björn Steinbrink:
> >"git merge" is about merging histories. --squash and the A..B you
> >suggest make it degenerate into merging changes (and you can't
> >record that using the commit DAG). So that messes things up
> >conceptually.
> 
> I know, this is the one "feature" of CVS that I sometimes miss in
> Git, that I cannot "merge" just parts of a history, and have that
> recorded in the history tree. I know it's wrong, I know I could do
> it better, but sometimes it's the shortcut that would make life
> easier for me. :-)

Hm, does CVS really record the fact that things were merged? I've never
seriously used CVS, so I have no idea... And if it does, is it just the
same thing as the svn "merge"-tracking?

> But the reason I mentioned it was because of the discussion on
> whether the "reverse rebase" should be an option to "cherry-pick" or
> not, and I mentioned that it could just as well be "merge" since it
> can be used to throw away history as well.

OK, and I disagreed because I think that "merge --squash" is already
wrong. And given your comment below about retiring "merge --squash", I
guess we're in agreement now, right?

> >Anyway, "git merge" with a range simply makes no sense at all
> >given how git's merge works (opposed to svn's idea of merging,
> >which is about changes, not about histories). If you want a squash
> >flag, tell cherry-pick to handle ranges and teach such a flag to
> >it.
> 
> And tell "merge" to tell me that if I try, so that if I try
> 
>   $ git merge A..B
> 
> I would get a message saying something like
> 
>   Cannot merge a range of commits. Try "git cherry-pick A..B" or
>   "git rebase --reverse A..B".

Hm, for an error message that "range of commits" is probably on the edge
of being confusing. After all "git merge B" will create a new commit M
that "says" that M^1..M^2 was merged to M^1. But I can't come up with a
better error message either.

> And perhaps we could also in the same way retire --squash?
> 
>   $ git merge --squash B
>   The "--squash" option is obsolete. Please use "git cherry-pick
>   --squash B".

git cherry-pick --squash ..B # Not just B itself, but the whole range

> (with a transition period where it would just call the other). Or
> whatever the options to simulate the old behaviour would be. This
> would make it clearer that "merge" preserves history while
> "cherry-pick" and "rebase" do not.

I'd certainly like that.

Bjoern

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-10  7:43                     ` Björn Steinbrink
@ 2009-12-10 17:20                       ` Junio C Hamano
  2009-12-11 11:07                         ` Björn Steinbrink
  0 siblings, 1 reply; 43+ messages in thread
From: Junio C Hamano @ 2009-12-10 17:20 UTC (permalink / raw)
  To: Björn Steinbrink
  Cc: Michael S. Tsirkin, Andreas Schwab, Peter Krefting, Git Mailing List

Björn Steinbrink <B.Steinbrink@gmx.de> writes:

>> But at the conceptual level, "merge --squash" is a short-hand for this
>> command sequence:
>> 
>>     git rebase -i HEAD that-branch
>>     ... make everything except the first one into "squash"
>>     git checkout - ;# come back to the original branch
>>     git merge that-branch ;# fast forward to it
>> 
>> So after all, it is "merge it after squashing them".
>
> To me, that approach looks backwards,...

Yes, of course, but what you are missing (and I am at blame for forgetting
to mention the history behind this in the message you are responding to)
is that "merge --squash" to support a particular need/use case was done
way before "rebase -i" came into existence.

Here is how "merge --squash" is explained in the log message:

    git-merge --squash
    
    Some people tend to do many little commits on a topic branch,
    recording all the trials and errors, and when the topic is
    reasonably cooked well, would want to record the net effect of
    the series as one commit on top of the mainline, removing the
    cruft from the history.  The topic is then abandoned or forked
    off again from that point at the mainline.

A nicer workflow may be to use "rebase -i" to clean up the history before
even contemplating to integrate the topic to the mainline, instead of the
above "abandoning or forking off again", if you know today's git.  

But interactive was not available back then.  It was introduced at 1b1dce4
(Teach rebase an interactive mode, 2007-06-25), which is 1 year after
7d0c688 (git-merge --squash, 2006-06-23).

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-10 17:20                       ` Junio C Hamano
@ 2009-12-11 11:07                         ` Björn Steinbrink
  0 siblings, 0 replies; 43+ messages in thread
From: Björn Steinbrink @ 2009-12-11 11:07 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Michael S. Tsirkin, Andreas Schwab, Peter Krefting, Git Mailing List

On 2009.12.10 09:20:28 -0800, Junio C Hamano wrote:
> Björn Steinbrink <B.Steinbrink@gmx.de> writes:
> 
> >> But at the conceptual level, "merge --squash" is a short-hand for this
> >> command sequence:
> >> 
> >>     git rebase -i HEAD that-branch
> >>     ... make everything except the first one into "squash"
> >>     git checkout - ;# come back to the original branch
> >>     git merge that-branch ;# fast forward to it
> >> 
> >> So after all, it is "merge it after squashing them".
> >
> > To me, that approach looks backwards,...
> 
> Yes, of course, but what you are missing (and I am at blame for forgetting
> to mention the history behind this in the message you are responding to)
> is that "merge --squash" to support a particular need/use case was done
> way before "rebase -i" came into existence.

Hm? You started explaining that "merge --squash" would be right because
you can do it via some command sequence that involves rebase -i and then
merge. I said that using that rebase+merge sequence as an argument for
the choice of the name is wrong. It would even have made more sense to
me if you said:

git merge that-branch
git reset --soft HEAD^
git commit -C ORIG_HEAD

Which is "merge, but then drop the extra parents", which pretty close to
what "merge --squash" does (and that sequence even gets it right not to
rewrite that-branch).

I'm not arguing that you shouldn't have chosen "merge --squash" to do
that. You couldn't possibly foresee the future and that git might get
rebase -i or maybe at some day cherry-pick -i <range>. I'm just saying
that in retrospective, it's sad that merge doesn't always mean "merge
histories", but that --squash makes it degenerate to "merge changes".

I don't see why you're trying to defend the choice of "merge --squash"
using a IMHO rather weird command sequence that happens to involve
"merge", using commands that weren't present when "merge --squash" was
added, but at the same ignore the "cherry-pick -i <range>" command git
might learn in the near future, which allows for a much saner
explanation:

git cherry-pick -i ..that-branch
... make everything except the first one into "squash"

And given that, one could add a --squash flag to cherry-pick that makes
it do the "squash everything" itself, allowing it to be a bit smarter
about the whole thing, because it could use a three-way merge
internally, instead of cherry-picking all the individual commits. Making
"git cherry-pick --squash ..that-branch" the same as "git merge --squash
that-branch".

> A nicer workflow may be to use "rebase -i" to clean up the history before
> even contemplating to integrate the topic to the mainline, instead of the
> above "abandoning or forking off again", if you know today's git.  

Well, I'm not saying that git should completely lose the abilitiy to do
something like "merge --squash", just that if it learns "git cherry-pick
<range>", it might as well get the --squash thing for cherry-pick, maybe
allowing for "merge --squash" to be phased out. And heck, having it as
an option to cherry-pick instead of merge would probably already help a
lot to make people realise that it won't remember that the changes got
"integrated". We've had people on #git that wondered why repeated "git
merge --squash" commands would try to merge the same stuff over and over
again, leading to the same conflicts every time. Because they didn't
realise that with --squash, "git merge" is no longer about merging
histories.

> But interactive was not available back then.  It was introduced at 1b1dce4
> (Teach rebase an interactive mode, 2007-06-25), which is 1 year after
> 7d0c688 (git-merge --squash, 2006-06-23).

Again, I'm not blaming you for having chosen that command back then.
Just saying that it might be better to have the same functionality in an
extended cherry-pick now.

Björn

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

* Re: [PATCH RFC] rebase: add --revisions flag
  2009-12-08 20:22 ` Junio C Hamano
                     ` (3 preceding siblings ...)
  2009-12-09 13:30   ` Matthieu Moy
@ 2009-12-13 22:47   ` David Kågedal
  4 siblings, 0 replies; 43+ messages in thread
From: David Kågedal @ 2009-12-13 22:47 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Michael S. Tsirkin

Junio C Hamano <gitster@pobox.com> writes:

> "Michael S. Tsirkin" <mst@redhat.com> writes:
>
>> Add --revisions flag to rebase, so that it can be used
>> to apply an arbitrary range of commits on top
>> of a current branch.
>
> I would suggest calling the option to invoke that hidden mode not
> "--revisions", but "--reverse" or "--opposite" or something of that
> nature, though.  It makes "rebase" work in different direction.

And there are no "revisions" in git. So using that term for anything
would only be confusing. Git has "commits" and various kinds of
references to them.

-- 
David Kågedal

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

end of thread, other threads:[~2009-12-13 22:47 UTC | newest]

Thread overview: 43+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-08 14:47 [PATCH RFC] rebase: add --revisions flag Michael S. Tsirkin
2009-12-08 16:08 ` Björn Steinbrink
2009-12-08 16:11   ` Michael S. Tsirkin
2009-12-08 16:41     ` Björn Steinbrink
2009-12-08 16:49       ` Michael S. Tsirkin
2009-12-08 19:13         ` Björn Steinbrink
2009-12-08 16:14   ` Michael S. Tsirkin
2009-12-08 16:37     ` Björn Steinbrink
2009-12-08 16:44       ` Michael S. Tsirkin
2009-12-08 19:11         ` Björn Steinbrink
2009-12-08 20:00           ` Michael S. Tsirkin
2009-12-09 13:19             ` Björn Steinbrink
2009-12-09 14:02               ` Michael S. Tsirkin
2009-12-09  4:51         ` Miles Bader
2009-12-08 20:22 ` Junio C Hamano
2009-12-08 20:29   ` Sverre Rabbelier
2009-12-09  5:30     ` Christian Couder
2009-12-09  6:52       ` Christian Couder
2009-12-09  9:08         ` Sverre Rabbelier
2009-12-09  8:47   ` Peter Krefting
2009-12-09  9:37     ` Michael S. Tsirkin
2009-12-09 10:52       ` Peter Krefting
2009-12-09 11:22         ` Björn Steinbrink
2009-12-09 11:48           ` Andreas Schwab
2009-12-09 12:06             ` Björn Steinbrink
2009-12-09 12:07               ` Michael S. Tsirkin
2009-12-09 13:06                 ` Björn Steinbrink
2009-12-09 19:46                   ` Junio C Hamano
2009-12-10  7:43                     ` Björn Steinbrink
2009-12-10 17:20                       ` Junio C Hamano
2009-12-11 11:07                         ` Björn Steinbrink
2009-12-09 13:20           ` Peter Krefting
2009-12-09 13:41             ` Björn Steinbrink
2009-12-10  8:43               ` Peter Krefting
2009-12-10 11:08                 ` Björn Steinbrink
2009-12-09 10:38   ` Michael S. Tsirkin
2009-12-09 10:55     ` Matthieu Moy
2009-12-09 13:30   ` Matthieu Moy
2009-12-09 13:45     ` Michael S. Tsirkin
2009-12-09 14:01       ` Björn Steinbrink
2009-12-09 14:12         ` Michael S. Tsirkin
2009-12-09 20:10     ` Junio C Hamano
2009-12-13 22:47   ` David Kågedal

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.