threads / discuss / 2822

git-merge fails when trying to merge from a tag

Subject: git-merge fails when trying to merge from a tag

## tl;dr

3 messages between Dec 13, 2005 and Dec 14, 2005.

replies: 2people: 2as markdown or json

Carl Baldwin· Dec 13, 2005, 17:55 UTC · lore
Greetings,

I just tried to merge using a tag object. I expected this to work just fine since the tag refers to a commit object and is therefore committish. The very same merge command except with '^{}' appended to the tag name to select the commit object worked just fine. Below you'll find some interesting output.

Cheers, Carl

PS I used git-bisect for the first time this morning. I was VERY impressed. Anyway, on to the output...

% git --version git version 0.99.9m

% git merge "Merging release-0.3.1" HEAD refs/tags/release-0.3.1 Trying really trivial in-index merge... fatal: Merge requires file-level merging Nope. Merging HEAD with refs/tags/release-0.3.1 Merging: df17837d378c5ee07a26c97ac1bfc3fb3f7bacbb Fix test of string f2aa1e01ae0f1b0ea9354f2ea2c7444b5efc8ac5 Merging release-0.2.1 found 1 common ancestor(s): 43c6310a463aee1c2cbd882b81a596e429bc7f6c Commit msg Auto-merging scripts/config.sh

fatal: 4c29c70d1d290807c2757eabaefb607b8fd7b595 is not a valid 'commit' object

% git-cat-file tag 4c29c70d1d290807c2757eabaefb607b8fd7b595 object f2aa1e01ae0f1b0ea9354f2ea2c7444b5efc8ac5 type commit tag release-0.3.1 tagger Carl N. Baldwin <carl@ecbaldwin.net> 1134493064 -0700 ... (The rest of the tag object looks just as you'd expect)

% git checkout -f # To reset changes done by failed merge % git merge "Merging release-0.3.1" HEAD refs/tags/release-0.3.1^{} Trying really trivial in-index merge... fatal: Merge requires file-level merging Nope. Merging HEAD with refs/tags/release-0.3.1^{} Merging: df17837d378c5ee07a26c97ac1bfc3fb3f7bacbb Fix test of string f2aa1e01ae0f1b0ea9354f2ea2c7444b5efc8ac5 Merging release-0.2.1 found 1 common ancestor(s): 43c6310a463aee1c2cbd882b81a596e429bc7f6c Commit msg Auto-merging scripts/config.sh

Merge 5612809ea11c9709e3a5282f8002c1f993e127d6, made by recursive.
 scripts/config.sh |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 Carl Baldwin                        Systems VLSI Laboratory
 Hewlett Packard Company
 MS 88                               work: 970 898-1523
 3404 E. Harmony Rd.                 work: Carl.N.Baldwin@hp.com
 Fort Collins, CO 80525              home: Carl@ecBaldwin.net
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Junio C Hamano· Dec 13, 2005, 19:21 UTC · re: Carl Baldwin · lore

Re: git-merge fails when trying to merge from a tag

Carl Baldwin <cnb@fc.hp.com> writes:
> I just tried to merge using a tag object.
Thanks for the report.
> % git merge "Merging release-0.3.1" HEAD refs/tags/release-0.3.1

Once I considered changing commit-tree to take any committish after -p, but thought the command is a low level primitive and the user should know what he is doing, but apparently, git-merge does not know what it is doing ;-).

In fact, I never use "merge" myself, and haven't noticed this breakage until now (you would notice that the Everyday document never talks about "git merge"). Instead, I always do this:

	$ git pull . tag release-0.3.1

But you are right. It is advertised as the end-user command and demonstrated in the tutorial.

How about this patch? I haven't looked at what (old) git-resolve and git-octopus commands do --- they may need similar parameter massaging.

-- >8 -- [PATCH] allow merging any committish

Although "git-merge" is advertised as the end-user level command (instead of being a "git-pull" backend), it was not prepared to take tag objects that point at commits and barfed when fed one. Sanitize the input while we validate them, for which we already have a loop.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
diff --git a/git-merge.sh b/git-merge.sh
index a221daa..d25ae4b 100755
--- a/git-merge.sh
+++ b/git-merge.sh
@@ -97,11 +97,14 @@ head=$(git-rev-parse --verify "$1"^0) ||
 shift
 
 # All the rest are remote heads
+remoteheads=
 for remote
 do
-	git-rev-parse --verify "$remote"^0 >/dev/null ||
+	remotehead=$(git-rev-parse --verify "$remote"^0) ||
 	    die "$remote - not something we can merge"
+	remoteheads="${remoteheads}$remotehead "
 done
+set x $remoteheads ; shift
 
 case "$#" in
 1)
Carl Baldwin· Dec 14, 2005, 00:00 UTC · re: Junio C Hamano · lore

Re: git-merge fails when trying to merge from a tag

On Tue, Dec 13, 2005 at 11:21:19AM -0800, Junio C Hamano wrote:
Show 18 quoted lines
> Carl Baldwin <cnb@fc.hp.com> writes:
> 
> > I just tried to merge using a tag object.
> 
> Thanks for the report.
> 
> > % git merge "Merging release-0.3.1" HEAD refs/tags/release-0.3.1
> 
> Once I considered changing commit-tree to take any committish
> after -p, but thought the command is a low level primitive and
> the user should know what he is doing, but apparently, git-merge
> does not know what it is doing ;-).
> 
> In fact, I never use "merge" myself, and haven't noticed this
> breakage until now (you would notice that the Everyday document
> never talks about "git merge").  Instead, I always do this:
> 
> 	$ git pull . tag release-0.3.1

I've done this also. Personally, I feel a little more in control with a fetch, merge, tag type of flow. Maybe its just me but I couldn't get used to pull doing it all for me so I like to split the operation so that I can easily run a diff-tree between the two if I want after performing the fetch.

While we're on the subject. It might be nice if merge behaved a little more like pull (without the fetch of course). At the moment, I've got to give merge three arguments whereas pull is happy with just one of them.

So, sometimes I would like to type this % git merge <head>

much like one would type % git pull . <head>

Rather than typing % git merge "Message" HEAD <head>

But, this might not be an easy API change to make. I suppose I could just type 'git pull . <head>' and be satisfied but my thought process tells be that I'm merging branches rather than pulling so I usually don't think about it. I'm really just typing my stream of thought at this point so I'll wrap it up.

Thanks, Carl

Show 40 quoted lines
> But you are right.  It is advertised as the end-user
> command and demonstrated in the tutorial.
> 
> How about this patch?  I haven't looked at what (old)
> git-resolve and git-octopus commands do --- they may need
> similar parameter massaging.
> 
> -- >8 --
> [PATCH] allow merging any committish
> 
> Although "git-merge" is advertised as the end-user level command
> (instead of being a "git-pull" backend), it was not prepared to
> take tag objects that point at commits and barfed when fed one.
> Sanitize the input while we validate them, for which we already
> have a loop.
> 
> Signed-off-by: Junio C Hamano <junkio@cox.net>
> ---
> diff --git a/git-merge.sh b/git-merge.sh
> index a221daa..d25ae4b 100755
> --- a/git-merge.sh
> +++ b/git-merge.sh
> @@ -97,11 +97,14 @@ head=$(git-rev-parse --verify "$1"^0) ||
>  shift
>  
>  # All the rest are remote heads
> +remoteheads=
>  for remote
>  do
> -	git-rev-parse --verify "$remote"^0 >/dev/null ||
> +	remotehead=$(git-rev-parse --verify "$remote"^0) ||
>  	    die "$remote - not something we can merge"
> +	remoteheads="${remoteheads}$remotehead "
>  done
> +set x $remoteheads ; shift
>  
>  case "$#" in
>  1)
> 
> 
-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 Carl Baldwin                        Systems VLSI Laboratory
 Hewlett Packard Company
 MS 88                               work: 970 898-1523
 3404 E. Harmony Rd.                 work: Carl.N.Baldwin@hp.com
 Fort Collins, CO 80525              home: Carl@ecBaldwin.net
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

← back to recent threads