There are many topics on bundle
and unbundle
repository, but I cannot find a way to restore it with reflog.
git bundle create mybundle --all
Now git clone mybundle
clears reflog and git init && git bundle unbundle mybundle
does... nothing?
Could someone explain why unbundle
command seems to have no effect and what is the best way of pack/unpack full repository with a reflog other than copy .git
directory?
CodePudding user response:
Bundles, as read and written by git bundle
, implement the git fetch
protocol in two steps, rather than in one step. This allows you to do the operation even if there's no working network connection between two repositories. For instance, suppose you have computer A in a lab, and computer B that operates a telescope atop a mountain where there's no Internet yet. You want to bring a software update to computer B, so you build a "bundle" on computer A in the lab, write it to a USB key or whatever, drive up the mountain, and use that to update computer B.
If you did have a working network, you'd drive up the mountain (or just log in remotely) and run git fetch
on computer B. This would not copy the reflogs from computer A. The reflogs of a Git repository are specific to that repository, and there are two separate repositories here: the one on computer A holds their reflogs, and the one on computer B holds their (different) reflogs.
Since git bundle
is duplicating what git fetch
would do, this does not update reflogs by design.
git bundle unbundle mybundle
does... nothing?
It runs git index-pack
. This is not meant for humans to use: it's there for git fetch
to run.
what is the best way [to copy] a reflog ...
A reflog is meant for, and maintained by, commands operating on the repository locally. Copying the entire .git
directory copies the repository wholesale including the reflog and that's the only "normal user" way to do this. You could use git reflog show
to dump out an existing reflog on repository A, followed by a sequence of git update-ref
commands to add new entries on repository B, but these would be new entries with new dates, not copies of existing entries.
In short, repositories are not meant to be shared. Commits are meant to be shared, but not the repositories that contain them: each repository is private.