I cloned a project from github with git clone –mirror. That left me with a repository with a packed-refs file, a .pack and an .idx file. For developement purposes I want to look at the loose objects, so I unpacked the objects with git unpack-objects < <pack file> which worked fine (I unpacked the pack file into a new repo if you’re wondering). Only thing is that refs/heads/ is still empty, all the refs are still only in packed-refs but I need them in refs/heads/.
I wasn’t able to find a command that would extract or unpack those references and I can somehow not believe that I would have to do this by hand (or via pipes).
So actually I have two questions:
- Is there an easy way to “restore” refs from packed-refs?
- If not, why isn’t there? If there’s a command for unpacking objects, what is the reasoning behind not providing the same for refs (don’t forget that there’s even a command git pack-refs…)
Thanks for any tips and ideas.
The short answer is “no” – there is no “easy way” to unpack the refs the way you’re asking.
The slightly longer answer is, each ref is just a 41-byte text file (40 byte SHA1 in hex + newline) in a specific path, so the “hard” version just requires something like this in your
~/.gitconfig:Took a little trickiness to figure out how to get it to work properly, but there you go! Now you have ‘git unpack-refs’ and it does what you expect, and as a bonus it even works with $GIT_DIR if that’s set (otherwise it assumes you’re in the root of the git tree). If you haven’t read up on git aliases, https://git.wiki.kernel.org/index.php/Aliases is a great reference and even includes an example ‘git alias’ extension you can use to extend your own aliases.