git查找来自“工作树"的提交 [英] git find commit from "working tree"

查看:70
本文介绍了git查找来自“工作树"的提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设某人克隆了一个git存储库并删除了.git文件夹.有没有办法恢复他们正在进行的提交?这与恢复.git文件夹的最佳方法

Suppose a person cloned a git repository and deleted the .git folder. Is there a way to recover which commit they were on? This isn't a duplicate of Best way to restore .git folder or Can deleted .git be restored?, because years have past since this event. I'm now trying get it back under git to update it to a new version. However, changes may have been introduced in those years, that I need to merge/rebase onto the new version.

我目前的想法是:

  1. 使用 git clone --bare
  2. 将当前存储库从github克隆到另一个文件夹中
  3. 使用 git config --local --bool core.bare false
  4. 将存储库标记为非裸露
  5. 将文件从神秘版本复制到此文件夹中
  6. 将当前提交哈希值保存在工作树上的差异
  7. 将HEAD更新为HEAD ^(不十分确定如何在不修改工作树的情况下执行此步骤.可能会切换回裸机,签出HEAD ^切换回非裸机吗?我也阅读了有关git symbolic-ref管道的信息但不知道如何使用)
  8. 重复步骤4-5,直到从根本上结束
  9. 选择具有最小大小的差异.这应该很好地近似于此代码与之不同的提交.在该提交周围搜索确切的分歧点.

有更好的方法吗?有一个semver,但是它没有更新太多,因此只能将范围缩小到一两年左右.我不相信存储库有太多更改,所以我猜有完全匹配的文件.也许我可以使用这些信息来缩小可能的提交范围?谢谢!

Is there a better way? There's a semver, but it wasn't updated very much so it only cuts down the range to around a year or two. I don't believe the repository was changed much, so I'd guess there are exact matching files. Maybe I could use that information to narrow down the possible commits? Thanks!

推荐答案

我会这样做:

  1. 将实际源提交到某个分支(例如 _tmp _ ),以使索引很干净

迭代所有可能的提交(例如 git rev-list master )并检查差异

iterate over all possible commits (e.g. git rev-list master) and check the diff

<代码>git rev-list主|同时阅读转速;做git diff"$ rev""_tmp"&&回声这是$转!"完毕

_tmp _ 包含在存储库中未跟踪的文件时, git diff 将永远不会成功,因此您必须分析差异(例如,具有最低 wc的差异)-l 获胜).

When _tmp_ contains files which are untracked in the repository, the git diff will never succeeded and you have to analyze the diffs (e.g. this with lowest wc -l wins).

这篇关于git查找来自“工作树"的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆