Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way in git to push the reflog?

Tags:

git

git-push

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?

like image 645
Alexander Bird Avatar asked May 30 '13 17:05

Alexander Bird


People also ask

Which command is used to update Reflog git?

Git keeps track of updates to the tip of branches using a mechanism called reference logs, or "reflogs." Many Git commands accept a parameter for specifying a reference or "ref", which is a pointer to a commit. Common examples include: git checkout. git reset.

Can you push to upstream branch?

Push a new Git branch to a remote repo Create a new branch with the branch, switch or checkout commands. Perform a git push with the –set-upstream option to set the remote repo for the new branch. Continue to perform Git commits locally on the new branch.

How do I push to a specific repo in git?

To push the commit from the local repo to your remote repositories, run git push -u remote-name branch-name where remote-name is the nickname the local repo uses for the remote repositories and branch-name is the name of the branch to push to the repository. You only have to use the -u option the first time you push.

Is git Reflog local?

The reflog is strictly local and isn't part of the repository. It's also not included in pushes, fetches, or clones. Git uses the git reflog tool to keep track of changes made to branch tips. It lets you go back to any commit, even if it isn't referenced by any branch or tag.


2 Answers

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....')

like image 81
Yawar Avatar answered Oct 03 '22 06:10

Yawar


In short, what you need is just backup .git/logs.

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.

like image 41
dyng Avatar answered Oct 03 '22 08:10

dyng