I'm looking for a way to show the contents of a file in my repository at some point back in time. I use the following command:
$ git show "origin/master@{1 year ago}:A/B/C/main.h"
However, 1 year ago 'main.h' existed at X/Y/Z/main.h
. So, if I adjust to this instead:
$ git show "origin/master@{1 year ago}:X/Y/Z/main.h"
This shows me file content but it's not the correct content at that point in time (I haven't verified what version of the content is actually shown, but it seems recent... perhaps the first version of the content after the rename). The rename is confusing git show
and I'm not sure how to make it work.
I found this SO question which seems to have a similar question. I'd like git show
to work for this instead of git log
if possible (since log will only show me the diff with -p
and I want to see the full content)
Can anyone help me figure out the correct way to do this? It seems that renames throw a big wrench in Git's cogs.
Update 1
This seems to be an issue with using the branch@{date}
revision specification. If I grab a SHA1 hash from 1 year ago and run the same command on it, it works fine:
$ git show 8f6a0e7:X/Y/Z/main.h
So maybe I'm specifying my revision incorrectly?
Update 2
Apparently the problem is that revision by date relies on reflogs which expire and certainly don't go back a year in my case.
Because of this, I am only seeing the file's state as of about 4 weeks ago (since my reflog for origin/master does not go past this).
I originally thought that the rename was causing the issue, but it turns out to be my refspec. So actually my question is wrong: I know how to git show
on a file at any point in time regardless of rename, however I'd like to be able to do it with a relative time stamp that is calculated by git based on commit timestamps rather than relying on reflog.