简体   繁体   English

修复分裂错误的 git 子树

[英]Fixing a git subtree with a bad split

I have a git repo with a subtree that was set up years ago with a bad split commit that's throwing errors when I try to do a git subtree push .我有一个带有子树的 git repo,该子树是多年前建立的,当我尝试执行git subtree push时,错误的拆分提交会抛出错误。 The error I get looks something like this:我得到的错误看起来像这样:

git push using:  <remote>
fatal: ambiguous argument '<sha>^{commit}': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
could not rev-parse split hash <sha> from commit <sha>

When I look at the commit the error is complaining about, it's referring to:当我查看提交时,错误正在抱怨,它指的是:

  • a git-subtree-dir which is the name of the git prefix (fine)一个git-subtree-dir ,它是 git 前缀的名称(很好)
  • a git-subtree-split which refers to a hash that isn't there anymore( not fine).一个git-subtree-split指的是不再存在的散列(不好)。

I can assume that the initial split was made on a branch that was never merged back, and that any subsequent subtree pulls/pushes were done on another branch.我可以假设初始拆分是在一个从未合并回来的分支上进行的,并且任何后续的子树拉/推都是在另一个分支上完成的。 That commit is gone.那个承诺消失了。

The behavior of git-subtree when doing a push changes depending on git version:执行推送时git-subtree的行为会根据 git 版本而变化:

  • When I ran it with git 1.8, it would throw an error and delete the branch you're trying to push into on the remote repo(.).当我用 git 1.8 运行它时,它会抛出一个错误并删除你试图推送到远程 repo(.) 上的分支。
  • When running a somewhat later version (I don't know exactly which since I recently upgraded it), it would throw an error and work anyway.当运行稍晚一些的版本时(我不知道具体是哪个版本,因为我最近升级了它),它会抛出一个错误并且无论如何都能工作。 It would, however, take a very long time to run since it would go through the entire git repo history.但是,它会花费很长时间才能运行,因为它会遍历整个 git repo 历史记录。
  • When running the latest git version, it just throws the error and refuses to push.当运行最新的 git 版本时,它只是抛出错误并拒绝推送。

I tried running another split hoping to create another split and fix the issue:我尝试运行另一个拆分,希望创建另一个拆分并解决问题:

git subtree split --prefix=<prefix> --rejoin --ignore-joins

It created the new split, but I still get the same error when I try to do a subtree push.它创建了新的拆分,但是当我尝试进行子树推送时,我仍然遇到同样的错误。 It looks like the subtree command is still looking at the old split, and throwing an error.看起来 subtree 命令仍在查看旧的拆分,并抛出错误。

I'm running out of ideas, and I can't git subtree push anymore at all with the latest version of git.我的想法已经用完了,而且我不能再使用最新版本的 git 进行git subtree push了。 The only thing that comes to mind is to change the commit message from the old broken split, but it was made in 2018 and I don't think rebasing from a commit that old is a good idea.唯一想到的是更改来自旧的破碎拆分的提交消息,但它是在 2018 年制作的,我认为从旧的提交中变基不是一个好主意。

  • a git-subtree-split which refers to a hash that isn't there anymore(not fine).一个git-subtree-split指的是不再存在的散列(不好)。

Is it possible that this hash refers to a tag in the subtree repository that would have been git subtree pull ed?这个散列是否可能引用子树存储库中的标签,该标签本应被git subtree pull编辑? That would be the case if that subtree pull happened on an older version of Git (older than 2.32.0)如果该子树拉取发生在较旧版本的 Git(早于 2.32.0)上,情况就是如此

If so, you could try fetching that hash directly:如果是这样,您可以尝试直接获取该哈希值:

git fetch <subtree-repo> <hash>

and then retry your git subtree push .然后重试你的git subtree push

Git 2.39 and later would suggest that course of action, see https://github.com/gitgitgadget/git/commit/a23e0b69e2d25a893e187d86719de0b12b324579 and more precisely https://github.com/gitgitgadget/git/commit/1762382ab19dd6d5d84dd32e35e25c2b55b651f0 . Git 2.39 及更高版本会建议该操作过程,请参阅https://github.com/gitgitgadget/git/commit/a23e0b69e2d25a893e187d86719de0b12b324579更准确地说是https://github.com/gitgitgadget/git/commit/1762382ab19dd6d5d84dd32e35e25c21f50b

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM