git/list[1] front-page[2] threads[3] people[4] search[5] about
 

bug report: dates on diff

From
TLTodd Lewis <utoddl@email.unc.edu>
Date
Jul 6, 2017, 12:54 UTC
Message-ID
<b28bc109-b06f-0acf-960b-0b6761b0ee38@email.unc.edu>

I've run into what I think is a bug wrt date handling in "git diff". I have some historical data with which I'm attempting to populate a new git repo with back-dated commits. That appears to work. But referencing those commits by date with "git diff" does not. (I have no idea if the problem is limited to "git diff"; that's just where I've been banging my head.)

I'm using git version 2.9.4.

Below is a recreation of the problem from scratch using made up data. Note that the "git log" output shows the commits with the correct dates, but referencing "master@{any-date-before-git-init}" throws a "Warning: Log for 'master' only goes back to ..." and it erroneously selects the first commit (for 2010 in the example below, instead of the requested 2012 commit).

Here's the terminal session demonstrating the problem:
[utoddl@tarna tmp]$ mkdir gitbug
[utoddl@tarna tmp]$ cd gitbug

[utoddl@tarna gitbug]$ git init Initialized empty Git repository in /tmp/gitbug/.git/

[utoddl@tarna gitbug]$ for year in 2010 2011 2012 2013 2014 ; do
> echo "Charter for year $year." > charter_01-01-$year.txt
> touch -d"$year-01-01" charter_01-01-$year.txt
> done

[utoddl@tarna gitbug]$ ls -al total 20 drwxrwxr-x. 3 utoddl utoddl 160 Jul 6 08:14 . drwxrwxrwt. 19 root root 420 Jul 6 08:12 .. -rw-rw-r--. 1 utoddl utoddl 23 Jan 1 2010 charter_01-01-2010.txt -rw-rw-r--. 1 utoddl utoddl 23 Jan 1 2011 charter_01-01-2011.txt -rw-rw-r--. 1 utoddl utoddl 23 Jan 1 2012 charter_01-01-2012.txt -rw-rw-r--. 1 utoddl utoddl 23 Jan 1 2013 charter_01-01-2013.txt -rw-rw-r--. 1 utoddl utoddl 23 Jan 1 2014 charter_01-01-2014.txt drwxrwxr-x. 7 utoddl utoddl 200 Jul 6 08:12 .git

[utoddl@tarna gitbug]$ for year in 2010 2011 2012 2013 2014 ; do
> cp -p charter_01-01-$year.txt charter.txt
> git add charter.txt
> git commit --date="01-01-$year" -m "Committing charter for $year." charter.txt
> done
[master (root-commit) f5dc22c] Committing charter for 2010.
 Date: Fri Jan 1 07:19:45 2010 -0500
 1 file changed, 1 insertion(+)
 create mode 100644 charter.txt
cp: overwrite 'charter.txt'? y
[master dec8944] Committing charter for 2011.
 Date: Sat Jan 1 07:19:47 2011 -0500
 1 file changed, 1 insertion(+), 1 deletion(-)
cp: overwrite 'charter.txt'? y
[master cab72e0] Committing charter for 2012.
 Date: Sun Jan 1 07:19:48 2012 -0500
 1 file changed, 1 insertion(+), 1 deletion(-)
cp: overwrite 'charter.txt'? y
[master a0cbf74] Committing charter for 2013.
 Date: Tue Jan 1 07:19:49 2013 -0500
 1 file changed, 1 insertion(+), 1 deletion(-)
cp: overwrite 'charter.txt'? y
[master a75164c] Committing charter for 2014.
 Date: Wed Jan 1 07:19:53 2014 -0500
 1 file changed, 1 insertion(+), 1 deletion(-)
[utoddl@tarna gitbug]$ git log
commit a75164cdf56b5f7b10e7575ee4aa4f653656e456
Author: Todd Lewis <utoddl@email.unc.edu>
Date:   Wed Jan 1 07:19:53 2014 -0500
    Committing charter for 2014.
commit a0cbf74320f5b2309f697a48a8026328a998d787
Author: Todd Lewis <utoddl@email.unc.edu>
Date:   Tue Jan 1 07:19:49 2013 -0500
    Committing charter for 2013.
commit cab72e0902cb4130de49c5d898ef4cc2daf1e2d1
Author: Todd Lewis <utoddl@email.unc.edu>
Date:   Sun Jan 1 07:19:48 2012 -0500
    Committing charter for 2012.
commit dec8944f3c411f5f667cdfefee0609d38298489f
Author: Todd Lewis <utoddl@email.unc.edu>
Date:   Sat Jan 1 07:19:47 2011 -0500
    Committing charter for 2011.
commit f5dc22c636dd66a51e74dc01935a4879bd4946d6
Author: Todd Lewis <utoddl@email.unc.edu>
Date:   Fri Jan 1 07:19:45 2010 -0500
    Committing charter for 2010.

[utoddl@tarna gitbug]$ git diff master@{01-01-2012} charter.txt warning: Log for 'master' only goes back to Thu, 6 Jul 2017 08:19:45 -0400.

diff --git a/charter.txt b/charter.txt
index a18dbc9..29fedf9 100644
--- a/charter.txt
+++ b/charter.txt
@@ -1 +1 @@
-Charter for year 2010.
+Charter for year 2014.
[utoddl@tarna gitbug]$
-- 
   +--------------------------------------------------------------+
  / Todd_Lewis@unc.edu  919-445-0091  http://www.unc.edu/~utoddl /
 /      A man's home is his castle, in a manor of speaking.     /
+--------------------------------------------------------------+
Next: Junio C Hamano
Message 1 of 5 in “bug report: dates on diff”
  1. Todd LewisJul 6, 2017
  2. Junio C HamanoJul 6, 2017
  3. Todd LewisJul 6, 2017
  4. Junio C HamanoJul 6, 2017
  5. Junio C HamanoJul 6, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.