threads / discuss / 3725

Why would merge fail on a one-line addition?

Subject: Why would merge fail on a one-line addition?

## tl;dr

3 messages between Mar 25, 2006 and Mar 26, 2006.

replies: 2people: 3as markdown or json

Marc Singer· Mar 25, 2006, 22:26 UTC · lore
One of the unmerged files leaves this trail.
  elf@florence ~...git/linux-2.6 > git-ls-files --unmerged
  100644 6262d449120cdcde5db1b079806dcc0d9b5e6b7c 1       arch/arm/mach-lh7a40x/irq-lpd7a40x.c
  100644 dcb4e17b941990eabe8992680c9aa9b67afb6fd4 3       arch/arm/mach-lh7a40x/irq-lpd7a40x.c
  elf@florence ~...git/linux-2.6 > git-cat-file blob 6262d449120cdcde5db1b079806dcc0d9b5e6b7c > a
  elf@florence ~...git/linux-2.6 > git-cat-file blob dcb4e17b941990eabe8992680c9aa9b67afb6fd4 > b
  elf@florence ~...git/linux-2.6 > diff a b                                       21a22
  > #include "common.h"
Why would git have a problem with this?
Linus Torvalds· Mar 26, 2006, 00:31 UTC · re: Marc Singer · lore

Re: Why would merge fail on a one-line addition?

On Sat, 25 Mar 2006, Marc Singer wrote:
Show 12 quoted lines
> One of the unmerged files leaves this trail.
> 
>   elf@florence ~...git/linux-2.6 > git-ls-files --unmerged
>   100644 6262d449120cdcde5db1b079806dcc0d9b5e6b7c 1       arch/arm/mach-lh7a40x/irq-lpd7a40x.c
>   100644 dcb4e17b941990eabe8992680c9aa9b67afb6fd4 3       arch/arm/mach-lh7a40x/irq-lpd7a40x.c
> 
>   elf@florence ~...git/linux-2.6 > git-cat-file blob 6262d449120cdcde5db1b079806dcc0d9b5e6b7c > a
>   elf@florence ~...git/linux-2.6 > git-cat-file blob dcb4e17b941990eabe8992680c9aa9b67afb6fd4 > b
>   elf@florence ~...git/linux-2.6 > diff a b                                       21a22
>   > #include "common.h"
> 
> Why would git have a problem with this?

That whole file was apparently removed in the branch you are merging into (no stage 2). So what should the merge do? Throw away the one-liner addition (likely the correct thing) or maybe it should go somewhere else (ie maybe it wasn't removed outright, but the contents moved into another file, which would now need the one-line addition).

		Linus
Junio C Hamano· Mar 26, 2006, 01:32 UTC · re: Marc Singer · lore

Re: Why would merge fail on a one-line addition?

Marc Singer <elf@buici.com> writes:
Show 5 quoted lines
> One of the unmerged files leaves this trail.
>
>   elf@florence ~...git/linux-2.6 > git-ls-files --unmerged
>   100644 6262d449120cdcde5db1b079806dcc0d9b5e6b7c 1       arch/arm/mach-lh7a40x/irq-lpd7a40x.c
>   100644 dcb4e17b941990eabe8992680c9aa9b67afb6fd4 3       arch/arm/mach-lh7a40x/irq-lpd7a40x.c
> Why would git have a problem with this?

Your change and the change in the other branch are conflicting and git is helping you notice that.

The index has different #1 and #3 with #2 missing. This means the common ancestor (#1) had it, you (#2) _removed_ it, while the other branch (#3) modified it. Should it carry forward the modification (one line addition) made by the other branch and then remove the file to match yours, or should it remove it to match yours and ignore what the other branch did?

If you do not want to have that file in the result, record the path as such and make a commit. Since there is no #2, your working tree probably do not have that path, so:

        $ git update-index --remove arch/arm/mach-lh7a40x/irq-lpa7a40x.c

to resolve the path, resolve other conflicts if you have any and then commit the result.

However, this _might_ be a case where your line of development somewhere between the common ancestor and your tip moved that file somewhere else in which case you may want to do three-way merge between 6262d4 blob, your tip and dcb4e1 blob _and_ commit the result at the path you have. I do not know if that is the case and even if so I do not know where you have the corresponding file in your tree, but just as an example if you have it in arch/arm/mach-foo/irq-lpd7a40x.c, you would:

	$ cd arch/arm/mach-foo/
	$ common=$(git unpack-file 6262d4)
        $ his=$(git unpack-file dcb4e1)
        $ merge irq-lpd7a40x.c $common $his
        $ rm -f $common $his

And then eyeball the result of the merge, fix it up as necessary, and then:

	$ git update-index --remove arch/arm/mach-lh7a40x/irq-lpa7a40x.c
        $ git update-index arch/arm/mach-foo/irq-lpd7a40x.c
before committing.

← back to recent threads