Re: Question about "git pull --rebase"

Previous thread: git gc - out of memory by Simon Strandgaard on Saturday, November 14, 2009 - 12:26 pm. (4 messages)

Next thread: [gitk] [PATCH] Fix selection of tags. by Pat Thoyts on Saturday, November 14, 2009 - 6:21 am. (2 messages)
From: Francis Moreau
Date: Saturday, November 14, 2009 - 1:39 pm

hello,

Let's say I'm on a branch called 'foo'.

I tried to rebase this branch by using 'git pull --rebase'.

I first tried the following command:

    $ git pull --rebase origin master:foo
    remote: Counting objects: 5, done.
    remote: Total 3 (delta 0), reused 0 (delta 0)
    Unpacking objects: 100% (3/3), done.
    From /dev/shm/git/A
    ! [rejected]        master     -> foo  (non fast forward)

which failed.

Then I tried:

    $ git pull --rebase origin master

which worked.

Reading the man git-pull I would assume the 2 commands are equivalent
but obviously they're not.

So the question is: why ?

Thanks
-- 
Francis
--

From: Nanako Shiraishi
Date: Saturday, November 14, 2009 - 4:16 pm

With this command line, you are asking:

 1) Please first fetch master from origin and update the local 
    'foo' with it, but please fail if this doesn't fast forward;

 2) If the first step was successful, please rebase the current 
    branch on top of that commit.

If your current branch 'foo' doesn't fast forward, the first step 
should fail, and that is the failure you saw.

Your request doesn't make any sense. The first step would succeed 
only when your 'foo' doesn't have anything to replay on 'master' 
from origin, and the second step either isn't executed (when 'foo' 
has some commits), or it doesn't do anything (when 'foo' doesn't 

With this command line, you are asking:

 1) Please first fetch master from origin, but don't store it anywhere;

 2) Then on top of that fetched commit, please rebase the current branch.

That is a much saner request.

-- 
Nanako Shiraishi
http://ivory.ap.teacup.com/nanako3/

--

From: Francis Moreau
Date: Sunday, November 15, 2009 - 7:31 am

I see thanks.

Actually I've been confused by the following part of the git-pull man
page:

    A parameter <ref> without a colon is equivalent to <ref>: when
    pulling/fetching, so it merges <ref> into the current branch without
    storing the remote branch anywhere locally

So it sounds that both of the pull commands were equivalent whereas
they're not.

-- 
Francis
--

From: Johan 't Hart
Date: Saturday, November 14, 2009 - 4:29 pm

Francis Moreau schreef:
 > hello,
 >
 > Let's say I'm on a branch called 'foo'.
 >
 > I tried to rebase this branch by using 'git pull --rebase'.
 >
 > I first tried the following command:
 >
 >     $ git pull --rebase origin master:foo
 >     remote: Counting objects: 5, done.
 >     remote: Total 3 (delta 0), reused 0 (delta 0)
 >     Unpacking objects: 100% (3/3), done.
 >     From /dev/shm/git/A
 >     ! [rejected]        master     -> foo  (non fast forward)

When using a refspec, you usually mean to update a remote tracking 
branch, like refs/remotes/origin/master. Internally the refspec 
parameter is passed to git fetch, which fast-forwards your local 
tracking branch to match the remote branch.

With this command, you make git clear you want to fast-forward your 
branch refs/foo to match the remotes master branch, and then rebase your 
  current branch on that foo branch.

Foo probably is also your current branch. So what you probably want is 
to fetch the remotes master branch and rebase your current branch foo on 
it. You could do it this way:

 > Then I tried:
 >
 >     $ git pull --rebase origin master
 >
 > which worked.

This does not update any remote tracking branches, but it will rebase 
your foo branch on the remote master branch (which is what you want)
It could also be done with:

git pull --rebase origin master:origin/master

This will also update your remote tracking branch 
refs/remotes/origin/master to match the master branch on the remote 
repo. Your foo branch will then be rebased onto it.

 >
 > Reading the man git-pull I would assume the 2 commands are equivalent
 > but obviously they're not.
 >
 > So the question is: why ?

So, thats why :) They're not the same. Many words... Hope you 
understand... I hope I understood it well too..?

 >
 > Thanks

--

From: Francis Moreau
Date: Sunday, November 15, 2009 - 7:34 am

Looks like you did :)

I've been somehow confused by the git-pull man page, which says:

  A parameter <ref> without a colon is equivalent to <ref>: when
  pulling/fetching, so it merges <ref> into the current branch without
  storing the remote branch anywhere locally

So I thought that both of the commands were equivalent for 'git pull
--rebase'.

Thanks for the explanation.
-- 
Francis
--

From: Johan 't Hart
Date: Sunday, November 15, 2009 - 12:47 pm

Ah that part.

It means that
$ git pull --rebase origin master

means the same as:
$ git pull --rebase origin master:
(note extra colon at the end)

But not as:
$ git pull --rebase origin master:foo

It means that, when you give a refspec without a colon, it is the same 
as the refspec with the colon and without the right side.
--

From: Junio C Hamano
Date: Sunday, November 15, 2009 - 1:18 pm

Thanks for clearing it up.

I was puzzled by the above pointing-finger because I wanted to see where a
misinformation originated from to fix it at the source.  But still don't
see anything wrong with it.

Perhaps there was some other part of the manual that confused Francis to
think master: and master:foo are equivalent in that context?  I somehow
doubt it, but if there is one, we would need to fix that

In a separate thread, Thomas reported a gross misinformation in github
wiki he recently fixed:

    From: Thomas Rast <trast@student.ethz.ch>
    Subject: Re: [PATCH] pull: refuse complete src:dst fetchspec arguments
    Date: Sun, 15 Nov 2009 13:24:03 +0100
    Message-ID: <200911151324.05109.trast@student.ethz.ch>

Perhaps that page had some impact on this misunderstanding? 
--

From: Johan 't Hart
Date: Sunday, November 15, 2009 - 1:32 pm

My guess is that he was confused by '<ref>:' not meaning '<ref>:<ref>'. 
But I can't speak for him ofcource :)

Refspecs confused me too at the beginning... But knowing more and more 
about git, it seems that this part of the docs look OK to me.. At most 
an example might make things a little more clear, but I doubt it is 
necessary.

--

From: Francis Moreau
Date: Monday, November 16, 2009 - 5:00 am

Well, I don't remember how I started to think that:

<src>:

was equivalent to

<src>:<current-branch>

so, assuming I'm on branch 'foo':

$ git pull --rebase origin master:

was equivalent to

$ git pull --rebase origin master:foo

hence my confusion, which certainly due to my lack of attention

Perhaps, the definition of a refspec with an empty string for <dst>
might be clearer if defined on its own. For example, doing this in the
git-pull man page:

      <refspec>
           The format of a <refspec> parameter is an ....

           The remote ref that matches <src> is fetched,

                  if <dst> is not empty string, the local ref that
matches it is fast
                  forwarded using <src>. If the optional plus + is
used, the local ref is
                  updated even if it does not result in a fast forward update.

                  if <dst> is an empty string the fetched <src> is
merged into the
                  current branch without updating any local refs. In
this case the
                  optional + has no meaning.

           Note
                  ....

           Some short-cut notations are also supported.

               . A parameter <src> (<ref> without the ':<dst>' part)
is equivalent
                 to '<src>:' (a ref with an empty string for <dst>).


-- 
Francis
--

From: Francis Moreau
Date: Monday, November 16, 2009 - 5:17 am

BTW, this seems to be not exact.

$ git pull --rebase origin master:origin/master

fetches the 'master' branch on the remote repo, then creates a new
branch 'origin/master', which is updated with the fetched branch.

To update the remote tracking branch refs/remotes/origin/master, I
need to issue:

$ git pull --rebase origin master:remotes/origin/master

BTW2,  it looks like if the <dst> local ref doesn't exist the it will
be created. This something that appears very lately in the man page
(actually I can see the information only in the last example). This
could be part of the <refspec> defintion.

Thanks
-- 
Francis
--

Previous thread: git gc - out of memory by Simon Strandgaard on Saturday, November 14, 2009 - 12:26 pm. (4 messages)

Next thread: [gitk] [PATCH] Fix selection of tags. by Pat Thoyts on Saturday, November 14, 2009 - 6:21 am. (2 messages)