跨存储库获得统一的历史/指责/差异?

发布于 2025-01-10 18:55:59 字数 424 浏览 0 评论 0原文

由于我无法控制的原因,我有两个存储库(例如“R”和“S”),并且代码从一个存储库移至另一个存储库。更具体地说:

R:

根... a(添加“代码”文件夹)--- b(“代码”中的更改)... f(删除“代码”)...

S:

根... a(添加从 Rf 中删除“代码”)...d(“代码”中的更改)...

有什么方法可以轻松:

  • 获取存储库之间“代码”路径规范的差异,就好像 Rf 和 Sa 是结合起来(因为它们互相“抵消”,所以没有发生)?换句话说,查看 Rb 和 Sd 之间“代码”的差异?

  • 可以说跨存储库查看“git Blame”吗?

我知道理论上我可以过滤分支,将该代码拉出到子模块中,然后重建它,但这种情况已经发生了足够多的事情,这样做是不可行的。

For reasons out of my control, I have two repositories (say, "R" and "S"), and code was moved from one repository to another. More specifically:

R:

Root ... a (add "code" folder) --- b (changes in "code") ... f (remove "code") ...

S:

Root ... a (add "code" removed from Rf) ... d (changes in "code") ...

Is there any way to easily:

  • get a diff of the "code" pathspec between the repos, as if Rf and Sa are combined (and since they "cancel" each other out, didn't happen)? In other words, view a diff of "code" between Rb and Sd?

  • view a "git blame" so to speak across repositories?

I am aware that theoretically I could filter-branch, pull that code out into a submodule, and reconstruct it, but such an occurrence has happened enough that doing so isn't feasible.

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

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

发布评论

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

评论(1

-柠檬树下少年和吉他 2025-01-17 18:55:59

Git 使用提交,而不是文件。这使得您的“获取差异”问题变得简单,甚至微不足道:只需从一个存储库(或其克隆)到另一个存储库获取提交即可。提取不会进行任何提交,它只是将提取存储库中的所有提交添加到当前存储库。现在,您正在使用的存储库中(R 或 S 的克隆)将所有 R 和 S 提交到单个存储库中,现在您可以 git diff Rb 和 Sd 很简单。

git Blame 从 Sa 向后追踪到 Rf 比较困难,但如果您使用的是牺牲克隆,1 您可以使用 git Replace --graft 来“将历史粘合在一起”,这样 Git 根本不会真正查看提交 Sa。相反,它着眼于通过嫁接 Rf 作为其母体而制成的替代 Sa'。这仍然不困难,它只会影响使用克隆的每个人(因此需要一个牺牲克隆)。


1上面的获取技巧无需牺牲克隆即可完成,因为它唯一消耗的是磁盘空间。替换技巧会影响存储库的所有用户,因此通常不合适。

Git works with commits, not files. This makes your "get a diff" question easy, or even trivial: simply fetch the commits from one repository (or a clone thereof) to another. Fetching does not make any new commits, it just adds to the current repository all the commits that are in the fetched-from repository. So now you have, in the repository you're working in—a clone of either R or S—all of the R and S commits in a single repository, and now you can git diff Rb and Sd trivially.

Making git blame track backwards from Sa to Rf is harder, but if you're using a sacrificial clone,1 you can use git replace --graft to "glue the histories together", so that Git doesn't really look at commit Sa at all. Instead, it looks at a replacement Sa' that's made by grafting to Rf as its parent. That's still not difficult, it just affects everyone using the clone (hence the need for a sacrificial one).


1The fetch trick above can be done without a sacrificial clone, as the only thing it costs is disk space. The replace trick affects all users of the repository and thus is often unsuitable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文