From: Johan Herland <johan@herland.net>
To: git@vger.kernel.org
Subject: BUG?: git diff with 3 args consults work tree when it shouldn't
Date: Mon, 1 Aug 2011 19:35:11 +0200 [thread overview]
Message-ID: <201108011935.11373.johan@herland.net> (raw)
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@herland.net>
www.herland.net
next reply other threads:[~2011-08-01 17:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-01 17:35 Johan Herland [this message]
2011-08-04 2:54 ` Re* BUG?: git diff with 3 args consults work tree when it shouldn't Junio C Hamano
2011-08-04 18:58 ` [PATCH] diff -c/--cc: do not mistake "resolved as deletion" as "use working tree" Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201108011935.11373.johan@herland.net \
--to=johan@herland.net \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).