git-p4 提交失败,并显示“Not a valid object name HEAD~261”

发布于 2024-08-29 20:59:02 字数 893 浏览 3 评论 0原文

我有一个 git 存储库,我想将其镜像到 Perforce 存储库。我已经下载了 git-p4 脚本(没有给出弃用警告的最新版本),并且一直在使用它。我已经弄清楚如何从 Perforce 中提取更改,但当我尝试从 git 存储库同步更改时遇到错误。这是我到目前为止所做的:

git clone [email protected]:asdf/qwerty.git
git-p4 sync //depot/path/to/querty
git merge remotes/p4/master     (there was a single README file...)

所以,我已经将源复制到一个干净的新主管,得到了一个看起来很漂亮的合并文件树,并且 git status 显示我已经完成了-日期。但是:

> git-p4 submit
fatal: Not a valid object name HEAD~261
Command failed: git cat-file commit HEAD~261

git 邮件列表上的这个帖子似乎是相关的,但我无法弄清楚他们对所有 A、B 和 C 做了什么。有人可以澄清“不是有效的对象名称”的含义,以及我可以采取什么措施来解决该问题吗?我想做的就是定期将 origin/master 快照到 Perforce 中;不需要完整的历史记录。谢谢。

I've got a git repository that I'd like to mirror to a Perforce repository. I've downloaded the git-p4 script (the more recent version that doesn't give deprecation warnings), and have been working with that. I've figured out how to pull changes from Perforce, but I'm getting an error when I try to sync changes from the git repo back. Here's what I've done so far:

git clone [email protected]:asdf/qwerty.git
git-p4 sync //depot/path/to/querty
git merge remotes/p4/master     (there was a single README file...)

So, I've copied the origin to a clean, new director, got a lovely looking merged tree of files, and git status shows I'm up-to-date. But:

> git-p4 submit
fatal: Not a valid object name HEAD~261
Command failed: git cat-file commit HEAD~261

This thread on the git mailing list seems to be relevant, but I can't figure out what they're doing with all the A, B, and Cs. Could someone please clarify what "Not a valid object name" means, and what I can do to fix the problem? All I want to do is to periodically snapshot the origin/master into Perforce; a full history is not required. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笔芯 2024-09-05 20:59:02

9 年后,这个问题可能会随着 Git 2.23(2019 年第 3 季度)而消失。

请参阅 commit c3f2358(2019 年 5 月 28 日)作者:Mike Mueller (mdymike)
(由 Junio C Hamano -- gitster -- 合并于 提交 add59c4,2019 年 6 月 17 日)

p4 unshelve:修复 Windows 上的“Not a valid object name HEAD0

git p4 unshelve 因以下错误而失败:

fatal: Not a valid object name HEAD0
Command failed: git cat-file commit HEAD^0

(git version 2.21.0.windows.1, python 2.7.16)

git-p4 使用的 pOpen 调用来调用 git 命令可以采用以下任一方式:
字符串或数组作为第一个参数。
首选数组形式,因为将自动处理特定于平台的特殊字符转义。(https ://docs.python.org/2/library/subprocess.html
然而,extractLogMessageFromGitCommit 方法使用的是字符串
形式,因此 HEAD^0 参数中的插入符 (^) 字符未被使用
在 Windows 上转义。
插入符号恰好是转义字符,这就是 git 命令接收 HEAD0 的原因。

可以通过在命令中键入 ECHO HEAD^0 来确认该行为 -
提示符,发出 HEAD0

解决方案很简单,使用数组格式将命令传递给 fOpen,无论如何,推荐使用这种格式,并在此代码的其他部分中使用它。

9 years later, that issue might be gone with Git 2.23 (Q3 2019)

See commit c3f2358 (28 May 2019) by Mike Mueller (mdymike).
(Merged by Junio C Hamano -- gitster -- in commit add59c4, 17 Jun 2019)

p4 unshelve: fix "Not a valid object name HEAD0" on Windows

git p4 unshelve was failing with these errors:

fatal: Not a valid object name HEAD0
Command failed: git cat-file commit HEAD^0

(git version 2.21.0.windows.1, python 2.7.16)

The pOpen call used by git-p4 to invoke the git command can take either a
string or an array as a first argument.
The array form is preferred because platform-specific escaping of special characters will be handled automatically.(https://docs.python.org/2/library/subprocess.html)
The extractLogMessageFromGitCommit method was, however, using the string
form and so the caret (^) character in the HEAD^0 argument was not being
escaped on Windows.
The caret happens to be the escape character, which is why the git command was receiving HEAD0.

The behaviour can be confirmed by typing ECHO HEAD^0 at the command-
prompt, which emits HEAD0.

The solution is simply to use the array format of passing the command to fOpen, which is recommended and used in other parts of this code anyway.

计㈡愣 2024-09-05 20:59:02
fatal: Not a valid object name

应该意味着遥控器的 HEAD 指向了错误的引用。
换句话说,当您在 git 存储库中执行 P4 导入时,由于 SHA1 不正确,因此无法从该 git 存储库提交到 P4。为什么?我不知道。

这就是为什么,在您提到的线程中,用户:

  • 使用 --import-local 将 P4 存储库克隆到 B 中(“导入到 refs/heads/,而不是 < code>refs/remotes"),
  • 制作 B ( p4 存储库的 Git 克隆)a 裸存储库(因此您永远不会在其中工作,因为它的工作树是空的)
  • 修复 B 的 HEAD 以引用 B 中导入的 p4 主分支

  • 将 B 克隆到 C,一个非裸存储库(它的工作树不为空,您可以在其中工作)

B 仅用于初始导入。

其余的工作是在 C 中完成的(不存在 SHA1 不正确的问题),使用:

  • git-p4sync(另外在 C 中声明remotes/p4/master)到remotes/origin/*
  • git-p4提交
fatal: Not a valid object name

should mean that somehow the remote's HEAD points to an incorrect reference.
In other word, when you do a P4 import in a git repo, there is no way to submit from that git repo to P4, because of an incorrect SHA1. Why? I don't know.

That is why, in the thread you mention, the user:

  • clone the P4 repo into B with --import-local ("Import into refs/heads/, not refs/remotes"),
  • make B (the Git clone of the p4 repo) a bare repo (so you won't ever work in it, since its working tree is empty)
  • fix the HEAD of B to reference the p4 master branch imported in B

  • clone B into C, a non-bare repo (its working tree is not empty, you can work in it)

B was only there for the initial import.

The rest of the work is done in C (which has no issue of incorrect SHA1) with:

  • git-p4 sync (to declare in C remotes/p4/master in addition to remotes/origin/*)
  • git-p4 submit
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文