* [BUG] Move tracking in git diff is not as good as in git status
@ 2015-02-05 6:11 Scott Schmit
2015-02-05 7:39 ` Kyle J. McKay
0 siblings, 1 reply; 3+ messages in thread
From: Scott Schmit @ 2015-02-05 6:11 UTC (permalink / raw)
To: git mailing list
[-- Attachment #1: Type: text/plain, Size: 2149 bytes --]
In my use of git, I've noticed that "git status" is a lot better at
tracking moves and renames than "git diff", and this has recently caused
me a lot of headaches because a large number of moves were made in a
single commit, and it was very difficult to figure out which moves were
right and which were wrong.
I was using a fairly old version of git (1.7.11), but was able to
reproduce it on git 2.2.1.
Here's a reproduction recipe:
#!/bin/sh -x
# Fill in your git.git working tree path here:
GIT_GIT_REPO=
if [ -z "$GIT_GIT_REPO" ]; then
echo Fill in GIT_GIT_REPO
exit 1
fi
git init mv-test
cd mv-test/
# Pick two sample files of non-trivial size, since files that are too small
# never get tracked as moves.
cp ${GIT_GIT_REPO}/Documentation/asciidoc.conf .
cp ${GIT_GIT_REPO}/Documentation/blame-options.txt .
git add *
git commit -m "Start with two files from git.git/Documentation"
# Now rename them to something. Using 1 & 2 because they're nice & short.
git mv asciidoc.conf 1
git mv blame-options.txt 2
# Status sees the rename
git status
# So does the summary on the commit
git commit -m "Rename both files"
# And move tracking works
git diff -M --stat --summary HEAD~..
git diff -C --stat --summary HEAD~..
# Now "shift" the files
git mv 2 3
git mv 1 2
# Status knows what's going on
git status
# So does commit
git commit -m "2=1;3=2;"
# Neither of these commands get it (but -C gets a glimmer of the truth)
git diff -M --stat --summary HEAD~..
git diff -C --stat --summary HEAD~..
# Swap the files in place
git mv 3 tmp
git mv 2 3
git mv tmp 2
# Status gets it
git status
# Commit understands
git commit -m "Swap 2 & 3"
# Diff has no idea
git diff -M --stat --summary HEAD~..
git diff -C --stat --summary HEAD~..
---
At first, I thought it was because the "git mv" command recorded
something in the index that's lost once the commit happens.
To check if that was so, I went back to the commit in question, did a
"git reset HEAD~1" and "git add -A ." and git status understood what was
going on just fine.
--
Scott Schmit
[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 3891 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [BUG] Move tracking in git diff is not as good as in git status
2015-02-05 6:11 [BUG] Move tracking in git diff is not as good as in git status Scott Schmit
@ 2015-02-05 7:39 ` Kyle J. McKay
2015-02-05 19:01 ` Junio C Hamano
0 siblings, 1 reply; 3+ messages in thread
From: Kyle J. McKay @ 2015-02-05 7:39 UTC (permalink / raw)
To: Scott Schmit; +Cc: git mailing list
On Feb 4, 2015, at 22:11, Scott Schmit wrote:
> In my use of git, I've noticed that "git status" is a lot better at
> tracking moves and renames than "git diff", and this has recently
> caused
> me a lot of headaches because a large number of moves were made in a
> single commit, and it was very difficult to figure out which moves
> were
> right and which were wrong.
>
> I was using a fairly old version of git (1.7.11), but was able to
> reproduce it on git 2.2.1.
>
> Here's a reproduction recipe:
[...]
> # Now "shift" the files
> git mv 2 3
> git mv 1 2
[...]
> git commit -m "2=1;3=2;"
>
> # Neither of these commands get it (but -C gets a glimmer of the
> truth)
> git diff -M --stat --summary HEAD~..
> git diff -C --stat --summary HEAD~..
Ah, but did you try this:
git diff -B -M --stat --summary HEAD~..
> # Swap the files in place
> git mv 3 tmp
> git mv 2 3
> git mv tmp 2
[...]
> git commit -m "Swap 2 & 3"
>
> # Diff has no idea
> git diff -M --stat --summary HEAD~..
> git diff -C --stat --summary HEAD~..
Again, try this:
git diff -B -M --stat --summary HEAD~..
You can even use this:
git log -B -M --summary
to see them all.
While you can configure -M (or -C) to be on by default (see git config
diff.renames), there does not appear to be a config option to turn on -
B (--break-rewrites) by default.
And according to a recent thread [1], using -B and -M together can
produce incorrect results so you might not want them both on by
default anyway.
-Kyle
[1] http://thread.gmane.org/gmane.linux.kernel/1879635
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [BUG] Move tracking in git diff is not as good as in git status
2015-02-05 7:39 ` Kyle J. McKay
@ 2015-02-05 19:01 ` Junio C Hamano
0 siblings, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2015-02-05 19:01 UTC (permalink / raw)
To: Kyle J. McKay; +Cc: Scott Schmit, git mailing list
"Kyle J. McKay" <mackyle@gmail.com> writes:
> On Feb 4, 2015, at 22:11, Scott Schmit wrote:
>
>> In my use of git, I've noticed that "git status" is a lot better at
>> tracking moves and renames than "git diff", and this has recently
>> caused
>> me a lot of headaches because a large number of moves were made in a
>> single commit, and it was very difficult to figure out which moves
>> were
>> right and which were wrong.
>>
>> I was using a fairly old version of git (1.7.11), but was able to
>> reproduce it on git 2.2.1.
>>
>> Here's a reproduction recipe:
> [...]
>> # Now "shift" the files
>> git mv 2 3
>> git mv 1 2
> [...]
>> git commit -m "2=1;3=2;"
>>
>> # Neither of these commands get it (but -C gets a glimmer of the
>> truth)
>> git diff -M --stat --summary HEAD~..
>> git diff -C --stat --summary HEAD~..
>
> Ah, but did you try this:
>
> git diff -B -M --stat --summary HEAD~..
Yes, since f714fb84 (Enable rewrite as well as rename detection in
git-status, 2007-12-02) "git status" internally uses "-B -M".
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-02-05 19:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-05 6:11 [BUG] Move tracking in git diff is not as good as in git status Scott Schmit
2015-02-05 7:39 ` Kyle J. McKay
2015-02-05 19:01 ` Junio C Hamano
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).