【问题标题】:git push - where's my commit hash - git log is not showing in the history MIRROR repositorygit push - 我的提交哈希在哪里 - git log 未显示在历史 MIRROR 存储库中
【发布时间】:2017-05-07 14:49:51
【问题描述】:

我从 GIT 存储库克隆(最新)。此时仓库中的最新提交为:a10cb09

我使用以下命令进行克隆(我在我的小包装脚本中设置变量 r = 传递的第一个参数(对于 repo 名称又名 ansible):

  git clone git@github.com:mycompany/${r}.git

做了一些更改并执行了以下简单步骤:(即进行更改、添加文件/文件夹、提交和推送)我得到了一个新的提交哈希 a08c263(短)。

[arun@ip-10.20.30.33 ~/aks/always-latest-ws-repogroup/ansible] $ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)

    roles/mycompany.mycompany-ansible/
    mycompany-ansible.yml

nothing added to commit but untracked files present (use "git add" to track)
[arun@ip-10.20.30.33 ~/aks/always-latest-ws-repogroup/ansible] $ 


[arun@ip-10.20.30.33 ~/aks/always-latest-ws-repogroup/ansible] $ git add mycompany-ansible.yml roles/mycompany.mycompany-ansible

[arun@ip-10.20.30.33 ~/aks/always-latest-ws-repogroup/ansible] $ git commit -m "mycompany.mycompany-ansible playbook and role" mycompany-ansible.yml roles/mycompany.mycompany-ansible 
[master a08c263] mycompany.mycompany-ansible playbook and role
 14 files changed, 1771 insertions(+)
 create mode 100644 roles/mycompany.mycompany-ansible/README.md
 create mode 100644 roles/mycompany.mycompany-ansible/defaults/main.yml
 create mode 100644 roles/mycompany.mycompany-ansible/handlers/main.yml
 create mode 100644 roles/mycompany.mycompany-ansible/meta/.galaxy_install_info
 create mode 100644 roles/mycompany.mycompany-ansible/meta/main.yml
 create mode 100644 roles/mycompany.mycompany-ansible/tasks/apt_install.yml
 create mode 100644 roles/mycompany.mycompany-ansible/tasks/main.yml
 create mode 100644 roles/mycompany.mycompany-ansible/tasks/yum_install.yml
 create mode 100644 roles/mycompany.mycompany-ansible/templates/10-statsd.conf.j2
 create mode 100644 roles/mycompany.mycompany-ansible/templates/10-mycompany.conf.j2
 create mode 100644 roles/mycompany.mycompany-ansible/templates/proxy_auth_credentials.set.j2
 create mode 100644 roles/mycompany.mycompany-ansible/templates/telegraf.conf.wfcopy.j2
 create mode 100644 roles/mycompany.mycompany-ansible/templates/mycompany-proxy.conf.j2
 create mode 100644 mycompany-ansible.yml
[arun@ip-10.20.30.33 ~/aks/always-latest-ws-repogroup/ansible] $ 


[arun@ip-10.20.30.33 ~/aks/always-latest-ws-repogroup/ansible] $ git push
Counting objects: 21, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (19/19), done.
Writing objects: 100% (21/21), 18.65 KiB | 0 bytes/s, done.
Total 21 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:repogroup/ansible.git
   a10cb09..a08c263  master -> master
[arun@ip-10.20.30.33 ~/aks/always-latest-ws-repogroup/ansible] $  


[arun@ip-10.20.30.33 ~/aks/always-latest-ws-repogroup/ansible] $ git log -1 --pretty=format:%h 
a10cb09


[arun@ip-10.20.30.33 ~/aks/always-latest-ws-repogroup/ansible] $ git rev-parse a08c263
a08c263
fatal: ambiguous argument 'a08c263': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

当我去 Github 存储库查看我的最新更改时,它不存在。 git log 也没有显示我的提交(相反,它显示了在我提交之前位于顶部的提交哈希)。我错过了什么?

似乎我什至看不到使用 git rev-parse a08c263 的长哈希(小哈希)。

$ git remote -v
origin  git@github.com:mycompany/ansible.git (fetch)
origin  git@github.com:mycompany/ansible.git (push)

$ git reflog 
a10cb09 HEAD@{0}: clone: from git@github.com:mycompany/ansible.git

PS:如果我对位于 mycompany repo 组下的其他存储库执行相同的步骤,并且如果我遵循类似的步骤,所有这些 repo 都会在 github 中成功获得我的提交/推送更改。 p>

更新:我的浏览器页面之一仍处于打开状态。在我提交+推送之后,我能够看到我提交的更改(新哈希 a08c263 作为顶级回购级别的最新提交)。当我点击它时,它打开了这个附加的浏览器页面,我可以在其中看到完整的哈希以及文件夹/文件。如果我访问为我的提交打开的浏览器 URL,它仍然存在(所以 Git 确实保存了一些东西)但是单击存储库的根级别,即 ansible,最新的提交不是我的提交+推送(新哈希),而是它的列表a10cb09 作为最新的(每个快照是我新生成的哈希的父哈希)。见这里:

这带来了主要问题:

  1. 如果我还没有打开此浏览器页面,那么我将如何获得长哈希和我的文件夹/文件(内容)?

  2. 如果我从 github.com/mycompany/ansible (repo) 克隆,它是 ansible 存储库的镜像,实际上托管在 Phabricator 中(实际原始存储库克隆 URL 与我在我上面的小脚本),那么我应该使用什么命令/选项将我的新更改推送到原始 Phabricator ansible 存储库?

  3. 如果提交+推送在我结束时完成,为什么git log 和其他类似的git 命令没有显示任何针对我的新哈希的信息?

【问题讨论】:

  • 您是否有机会推送到源而不是您自己的存储库?由于您没有定义要推送的内容,因此它将默认为原始主机。什么是原产地? git remote -v
  • @Christia 但是为什么提交甚至不会显示在本地日志中?
  • 请发布git reflog的前几条
  • @Christia 我在帖子中添加了这些详细信息。我的意思是,我为其他存储库执行这些步骤,它们每次都显示我的提交。 ansible repo 也作为其他 repos 的兄弟 repo,但相同的步骤变成了上述问题。为了测试,我尝试重做另一个测试更改/添加/提交/推送到 2 个存储库,一个得到了我的更改,而 ansible 再次没有。如果来源不正确,那么它不应该向我显示最后一次提交哈希(在git push 输出中为a10cb09..a08c263 对吗)?还添加了git reflog 输出。我同意蒂姆 B 的观点。
  • 好的,这就是我找到的。 mycompany github.com 中的 repo 组有很多存储库(ansible 就是其中之一)。但是,所有其他存储库都托管在 github.com 本身上,但是我克隆的这个 ansible 存储库没有托管在 github.com 上。 ansible 在我的案例中,repo 托管在 Phabricator 中,并镜像到 Github.com(我从那里克隆)它。现在,阅读更多git 帮助,看起来,如果我已经完成了git push --mirror,那么它会起作用(??),现在,我怎样才能使用a08c263 哈希取回相同的文件夹/文件并再次尝试git push --mirror / -all,无需任何返工。

标签: git github git-commit git-log git-hash


【解决方案1】:

访问该链接仍然有效,显示我提交的文件/文件夹,但如果我单击 Github 中的根存储库,它不会显示我的提交是最新的

这意味着:

  • 远程仓库的默认分支不是master
  • 或某些挂钩(接收后?)将 HEAD 设置或重置为不同的 SHA1

我克隆的这个 ansible repo 没有托管在 github.com 上。在我的案例中,ansible repo 托管在 Phabricator 中,并镜像到 Github.com(从我克隆的地方)

这可以解释重置。

最大的担忧是如何将我的文件夹/文件从 a08c263 提交中恢复到我的工作区。 git log 或 git rev-parse 没有显示任何内容/抛出错误,因为根据 Git 不存在该哈希。

当然:从 github 克隆到另一个本地文件夹,将您以前的克隆文件夹添加为远程仓库,获取并挑选您的提交:

git clone https://github.com/... newfolder
cd newfolder
git remote add old ../path/to/first/clone
git fetch old
git cherry-pick a08c263
git push

但您需要确保您有权回推到 GitHub 存储库。

【讨论】:

  • 我同意你的结论。任何想法,如果那个 Github 链接(它仍然显示我完整的新哈希和文件夹和文件内容)仍然有效,那么为什么在命令行(终端窗口),我做了 git commit+push 没有显示任何关于那个新的信息哈希,而 Git 显示提交 URL。
  • @ArunSangal 在你提交的第一个本地仓库中[master a08c263]git status 向你展示了什么?
  • On branch master Your branch is up-to-date with 'origin/master'. nothing to commit, working tree clean 可能是因为,我已经推送了更改,所以推送的内容没有什么新内容,或者我刚刚清除了整个仓库(即新的 git 克隆到相同的文件夹结构)跨度>
  • @ArunSangal 所以我想 git log -1 没有显示你最新的提交? (考虑到它是“p-to-date with 'origin/master'”,这似乎是合乎逻辑的)。你能在git fetch 之后检查相同的git status 吗?你看到你的提交是git log --all --branches --oneline --decorate --graph吗?
  • 是的,上面五颜六色的 git log 命令没有列出我的新哈希。显示最新的哈希(这是我提交的新哈希的父哈希)。 git log -1 在我克隆它之前检查它时也没有列出我的提交。那么,有什么方法可以获取内容,因为每个快照的提交链接 URL 仍然显示文件夹/文件内容?该链接仍然显示来自git log 输出的顶部/最新哈希作为我的新哈希的父哈希(提交版本)
猜你喜欢
  • 1970-01-01
  • 2020-12-18
  • 1970-01-01
  • 2019-07-28
  • 1970-01-01
  • 2011-03-20
  • 1970-01-01
  • 2015-04-02
  • 2013-02-05
相关资源
最近更新 更多