BUG?: git diff with 3 args consults work tree when it shouldn't

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I'm viewing the combined diff of a merge commit where the correct 
resolution involved the removal of a conflicting file. In short, the 
(simplified) scenario is:

    A
   / \
  O   M
   \ /
    B

where commit O does not contain the file, branches A and B add 
conflicting versions of the file, and merge M removes the file (see 
below for a full command session illustrating the scenario).

When I view the combined diff of the merge (using "git diff M A B" or 
"git show M" ), it seems the resulting diff depends on the 
existence/contents of the file in my *current work tree*. I.e. if I 
checkout O or M (where the file is missing) before producing the diff, 
the result seems correct, but if I put a garbage version of the file in 
my work tree (without adding or committing it at all), the garbage shows 
up in the diff, as follows:

  $ git diff M A B
  diff --cc file
  index 34b6a0c,732c85a..0000000
  --- a/file
  +++ b/file
  @@@ -1,1 -1,1 +1,1 @@@
  - contents contributed by A
   -contents contributed by B
  ++garbage contents from my work tree

AFAICS, when producing combined diffs, the diff code should not look up 
the file in the current work tree, since the diff arguments refer to 
existing commits, and do not indicate that the work tree should be 
consulted at all.


...Johan


Example session illustrating the problem:

$ git init repo
Initialized empty Git repository in ./repo/.git/
$ cd repo
$ echo foo > foo
$ git add foo
$ git commit -m foo
[master (root-commit) c6d62c2] foo
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 foo
$ git checkout -b a
Switched to a new branch 'a'
$ echo spam > file
$ git add file
$ git commit -m spam
[a d2d3128] spam
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 file
$ git checkout -b b master
Switched to a new branch 'b'
$ echo eggs > file
$ git add file
$ git commit -m eggs
[b 72e8252] eggs
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 file
$ git checkout -b m
Switched to a new branch 'm'
$ git merge a
Auto-merging file
CONFLICT (add/add): Merge conflict in file
Automatic merge failed; fix conflicts and then commit the result.
$ git rm file
file: needs merge
rm 'file'
$ git commit -m merge
[m c096356] merge
$ git diff m a b
diff --cc file
index 34b6a0c,732c85a..0000000
deleted file mode 100644,100644
--- a/file
+++ /dev/null
$ ### HERE IS WHERE IT GOES WRONG:
$ echo xyzzy > file
$ git diff m a b
diff --cc file
index 34b6a0c,732c85a..0000000
--- a/file
+++ b/file
@@@ -1,1 -1,1 +1,1 @@@
- spam
 -eggs
++xyzzy



-- 
Johan Herland, <johan@xxxxxxxxxxx>
www.herland.net
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]