简体   繁体   English

在 `git git filter-repo -> git pull --allow-unrelated-histories` 之后有什么方法可以找回本地历史记录?

[英]any way to get back local history after `git git filter-repo -> git pull --allow-unrelated-histories`?

I may have discovered a great way to irrevocably delete valuable stuff.我可能发现了一种不可撤销地删除有价值的东西的好方法。 Is there any way I can undo steps 1-2?有什么方法可以撤消步骤 1-2 吗?

Background背景

  1. I had a large file in a commit that caused a push error, so I tried to delete it with:我在提交中有一个大文件导致推送错误,所以我尝试使用以下方法删除它:
git filter-repo --path <this big file>--invert-paths --force
  1. I tried to re-push the commit but git refused to do such without a pull from remote, which I did by:我试图重新推送提交,但 git 拒绝在没有远程拉动的情况下这样做,我是通过以下方式做到的:
git pull origin main --allow-unrelated-histories
  1. Now several files open in my editor are marked as missing, and many more are gone or overwritten in the file system.现在,在我的编辑器中打开的几个文件被标记为丢失,还有更多文件系统中的文件消失或被覆盖。 Here is the output of git reflog这是git reflog的 output
$ git reflog --all 
01eb3b2 (origin/main) refs/remotes/origin/main@{0}: fetch origin: storing head
5ba15dd (HEAD -> main) refs/heads/main@{0}: commit (initial): update before s6, working on laplace alpha coeff
5ba15dd (HEAD -> main) HEAD@{0}: commit (initial): update before s6, working on laplace alpha coeff
  1. For files that were not deleted by (1,2) above, I can actually see the history of uncommitted changes in Visual Studio Code using <changed file> (Explorer View)->Open Timeline .对于上面 (1,2) 未删除的文件,我实际上可以使用<changed file> (Explorer View)->Open Timeline Visual Studio Code 中未提交更改的历史记录。
    在此处输入图像描述 However, I cannot do this with the many new local files that were apparently deleted when the remote was pulled in (2).但是,我无法对许多新的本地文件执行此操作,这些文件在拉入遥控器时显然已被删除 (2)。 Is there any way to do this?有什么办法吗?

As stated by @torek in the comments, my usage of git above destroyed the newly-created files whose only history was overwritten in the local repo.正如@torek 在评论中所述,我在上面对 git 的使用破坏了新创建的文件,这些文件的唯一历史记录在本地存储库中被覆盖。

Therefore, the sequence of git commands described in the OP are irreversible.因此,OP 中描述的 git 命令序列是不可逆的。

However, the fail-safe noted below may represent the only lifeline for the huge number of users connecting to remote environments in Visual Studio Code, who realize too late the consequences of abusing basic git commands.然而,下面提到的故障安全可能是连接到 Visual Studio Code 远程环境的大量用户的唯一生命线,他们意识到滥用基本 git 命令的后果为时已晚。

Fail-safe for VSCode (>= 1.66) Remote Environments: VSCode (>= 1.66) 远程环境的故障安全:

So it turns out that even though I was developing inside a remote dev container, Visual Studio Code locally caches remote workspace changes since v.1.66 .所以事实证明,即使我在远程开发容器内进行开发, Visual Studio Code 也会在本地缓存自 v.1.66 以来的远程工作区更改 All I had to do was Local History: Find Entry to Restore to locate the change history for files which were deleted on remote file system by the git filter-repo command in the OP.我所要做的就是Local History: Find Entry to Restore以找到通过 OP 中的git filter-repo命令在远程文件系统上删除的文件的更改历史记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Git 中止“git pull origin master --allow-unrelated-history” - Git Aborting with "git pull origin master --allow-unrelated-histories" git pull --allow-unrelated-histories是如何工作的? - How exactly does git pull --allow-unrelated-histories work? 使用--allow-unrelated-histories查找Git版本 - Find Git version with --allow-unrelated-histories 如何在 Git 2.9 之前 git 合并无关历史(--allow-unrelated-history 不可用) - How to git merge unrelated history pre Git 2.9 (--allow-unrelated-histories isn't available) 如何解决“拒绝合并不相关的历史”? 我试过“git pull origin master --allow-unrelated-histories” - How to fix "refusing to merge unrelated histories"? I have tried "git pull origin master --allow-unrelated-histories" git merge --allow-unrelated-histories复制所有分支中的提交 - git merge --allow-unrelated-histories replicates commits in all branches 我需要更好地理解 Git pull origin master --allow-unrelated-histories - I need to understand Git pull origin master --allow-unrelated-histories better 无法使用git pull“找不到远程引用–-allow-unrelated-histories” - Fail to use git pull “Couldn't find remote ref –-allow-unrelated-histories” 使用 git filter-repo 清理 git 历史记录 - Using git filter-repo to clean up git history 使用--allow-unrelated-history 维护历史? - Maintaining history with --allow-unrelated-histories?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM