6

As you might have known that by default, git doesn't enable reflog updates for new bare repositories. The problem is, I have a long history repository but it was created before I set the flag "logAllRefUpdates" on, and now I want that information for another application to work.

How can I achieve that with minimal changes made to the existing repository. A very simple solution is pushing a new commit which I don't want to (!) :-)

instcode
  • 1,495
  • 14
  • 16

1 Answers1

2

The reflog is a relatively simple file format. Here's an example:

] cat .git/logs/HEAD|sed 's/\t/<TAB>/'
0000000000000000000000000000000000000000 5cfe4256d98af22a570c78c5e3048391a90f5f98 Joe User <foo@example.com> 1306427954 -0400<TAB>clone: from git://git.kernel.org/pub/scm/git/git.git

You can manually construct appropriate reflogs by following the same format:

previous-ref-or-zero new-ref User Name <user@email> unix-timestamp timezone\tmessage

Just create one of these for each ref. You can probably do this directly with git for-each-ref with an appropriate format string (thanks, Chris!)

bdonlan
  • 224,562
  • 31
  • 268
  • 324
  • Unfortunately, I've just tried and this doesn't work. You can try by first setting the core.logallrefupdates to default (disable) then creating a bare repo, and enabling logallrefupdate again, and... – instcode May 26 '11 at 17:12
  • 1
    Programs iterating over refs should use `git for-each-ref` instead of “dealing with both loose and packed refs”. – Chris Johnsen May 27 '11 at 03:13
  • 1
    In my case, git pack-refs returns nothing. However, I found an easier way to do is to clone that repo then copy the .git/logs to the bare-repo. The key of solving this problem is knowing where reflogs stored that I didn't know :). Thanks. – instcode May 27 '11 at 05:49