Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git can I view the reflog of a remote?

Tags:

git

Is it possible to view the reflog of a remote? That is, I want to know what the output of git reflog is on another remote machine.

Note, I am not asking for the reflog of remote-tracking branches (such as origin/master), I am asking for what reflog says on the other machine.

like image 642
Alexander Bird Avatar asked Apr 10 '12 23:04

Alexander Bird


People also ask

How do I see git Reflog?

git reflog directories can be found at . git/logs/refs/heads/. , . git/logs/HEAD , and also . git/logs/refs/stash if the git stash has been used on the repo.

Is 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.

What information does git Reflog?

DESCRIPTION. Reference logs, or "reflogs", record when the tips of branches and other references were updated in the local repository. Reflogs are useful in various Git commands, to specify the old value of a reference. For example, HEAD@{2} means "where HEAD used to be two moves ago", master@{one.


2 Answers

On the off chance that the remote machine is a github repository,

  1. First use Github’s Events API to retrieve the commit SHA.
    curl https://api.github.com/repos/<user>/<repo>/events

  2. Identify the SHA of the orphan commit-id that no longer exists in any branch.

  3. Next, use Github’s Refs API to create a new branch pointing to the orphan commit.

    curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d '{"ref":"refs/heads/D-commit", "sha":"<orphan-commit-id>"}' https://api.github.com/repos/<user>/<repo>/git/refs

    Replace <orphan-commit-id> in the above command with the SHA identified in step 2.

  4. Finally git fetch the newly created branch into your local repository.
    From there you can cherry-pick or merge the commit(s) back into your work.

Check out this article for an actual example.

like image 93
Błażej Czapp Avatar answered Sep 28 '22 13:09

Błażej Czapp


The answer is basically "no" (except on that machine), because the reflog is a log of locally-made re-assignments of some ref-name. Essentially, every time you run git update-ref -m msg <name> <target> the update is logged ... locally: .git/logs/<name> gets a line appended:

$ git update-ref -m foo HEAD HEAD^ $ tail -1 .git/logs/HEAD 2418b6ba8fd0289933c9351260a272b8e410867f 8d945134b0cead535d66af29c8eb4228b5dc3763 [redacted] <[redacted]> 1334106483 -0600     foo 

(the thing before the message, in this case foo, is not spaces but rather a tab; I expanded it for SO purposes). Conceptually, everything else that moves a branch tip invokes git update-ref to do it (some are shell scripts and literally do that, others just invoke the C code that does all the file-updating) ... and everything in .git/logs makes up the reflog.

If there were things in the underlying git:// and/or ssh:// protocols that let you get at the reflog, that would do it, but as far as I know there isn't.

like image 35
torek Avatar answered Sep 28 '22 12:09

torek