Alexander Bird
Alexander Bird

Reputation: 40639

How to git push the reflog?

Is there a way to push the reflog to a remote? This seems like it would be an incredibly useful thing to do, but I do not know of a way to do it. I'm envisioning something like git push --include-reflogs

In the end, I would want the remote to have a verbatim copy of the reflogs at the time of the push.

I tried using --mirror, but 1) I don't want to delete any branches from this particular remote except manually, 2) it still didn't copy the reflogs over to the remote.

Does anyone know if/how this can be done?

Upvotes: 8

Views: 5480

Answers (3)

dyng
dyng

Reputation: 3054

You can backup .git/logs which will backup the references to the commits (but not the commits or files themselves).

Actually, git stores reflog information under .git/log directory, you can do anything to them like open files in this directory with a text editor. If you remove this directory, all reflog disappears and if you recover it, the reflog will be back.

As far as I know, there is no builtin way to track the .git/logs. I have tried to move .git/log to working directory and make a symlink from .git directory to it. It works but not very well, because every time you do a commit, the HEAD moves and the .git/logs/HEAD changes, then you have a uncommited change now. The working directory will never be clean.

Upvotes: 4

Yawar
Yawar

Reputation: 11607

What you are really asking is, is there a way push around anonymous (that is, unreferenced) commit objects and their trees and blobs for backup purposes. Answer is no. Anonymous objects--objects that are only referenced by your reflog--are private to the local repo.

But--You can just copy the .git directory of any repo to do what you want. If the source repo is busy (e.g. commits are happening, or a garbage collection or a repack) at the time then you need to copy files and directories in the .git directory in a certain order. This is explained in various places but one example is http://article.gmane.org/gmane.comp.version-control.git/147354 ('If you want your rsync backup to be fine, you need to follow some ordering....')

Upvotes: 12

Guillaume Darmont
Guillaume Darmont

Reputation: 5018

Git reflog tracks HEAD changes of a single Git repository. Each clone has its own reflog. I can't figure out what you would do with a shared reflog (help someone remotely ?)

If you really need to track someone's reflog, you could dump the reflog content in a file using git reflog > dev1_reflog.txt and share dev1_reflog.txt (using git add dev1_reflog.txt; git commit -m "Adding dev1_reflog"; git push).

Upvotes: 0

Related Questions