git 我可以查看遥控器的 reflog 吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10098095/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:25:14  来源:igfitidea点击:

git can I view the reflog of a remote?

git

提问by Alexander Bird

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

是否可以查看遥控器的 reflog?也就是说,我想知道git reflog另一台远程机器上的输出是什么。

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

请注意,我不要求远程跟踪分支(如产地/主)的引用日志,我问什么reflog的另一台机器上

采纳答案by torek

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 msg <name> <target>更新时都会记录...本地:.git/logs/<name>附加一行:

$ 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-refto 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/logsmakes up the reflog.

(在这种情况下foo,消息之前的内容不是空格而是制表符;我出于 SO 目的对其进行了扩展)。从概念上讲,移动分支提示的所有其他内容都需要调用git update-ref来执行此操作(有些是 shell 脚本,实际上就是这样做的,其他的只是调用执行所有文件更新的 C 代码)……并且其中的所有内容都.git/logs构成了 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.

如果底层 git:// 和/或 ssh:// 协议中有一些东西可以让您访问 reflog,那就可以了,但据我所知没有。

回答by B?a?ej Czapp

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

如果远程机器是 github 存储库,则可能性很小,

  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-idthat 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 fetchthe newly created branch into your local repository.
    From there you can cherry-pick or merge the commit(s) back into your work.

  1. 首先使用 Github 的 Events API 来检索提交的 SHA。
    curl https://api.github.com/repos/<user>/<repo>/events

  2. 确定任何分支中不再存在的孤立提交 IDSHA

  3. 接下来,使用 Github 的 Refs API 创建一个指向孤立提交的新分支。

    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

    <orphan-commit-id>上述命令中的 SHA替换为步骤 2 中标识的 SHA。

  4. 最后git fetch将新创建的分支添加到您的本地存储库中。
    从那里你可以挑选或合并提交回到你的工作中。

Check out this articlefor an actual example.

查看本文以获取实际示例。

回答by JeanValjean

On GitHub, if you did by mistake a git push --forceon master before to fetch the merged changes and in the meanwhile the merged branch was deleted (yeah, it happened to me), you can look for the merged pull request and go to the Commitssection, e.g:

在 GitHub 上,如果您之前错误地git push --force在 master 上获取合并的更改,同时合并的分支被删除(是的,它发生在我身上),您可以查找合并的拉取请求并转到提交部分,例如:

enter image description here

在此处输入图片说明

Then you go on the last commit and click on the <>button (that has title "Browse the repository at this point in the history").

然后继续最后一次提交并单击<>按钮(标题为“在历史记录中的此时浏览存储库”)。

This will bring you to the "deleted" point of history. From here you can:

这会将您带到历史的“删除”点。从这里您可以:

  • create a new branch and then open a new pull request (recommended if the change comes from another repository).
  • open a new pull request (recommended for commits inside your repository).
  • 创建一个新分支,然后打开一个新的拉取请求(如果更改来自另一个存储库,则推荐)。
  • 打开一个新的拉取请求(推荐用于存储库内的提交)。