简体   繁体   English

Mercurial(Hg)可以告诉我分支或提交来自哪个远程吗?

[英]Can Mercurial (Hg) show me what remote a branch or a commit is from?

I have a Mercurial (Hg) repository with 2 remotes, let's call them default and upstream . 我有一个带有2个远程控制器的Mercurial(Hg)存储库,我们将其称为defaultupstream

I have pulled from both remotes and would like to know which commits/branches came from the remote called default and which commits/branches came from the remote called upstream . 我从这两个远程服务器都退出了,想知道哪些提交/分支来自远程服务器,称为default ,哪些提交/分支来自远程服务器,称为upstream How do I achieve this in Hg? 如何在汞中实现这一目标?

Ideally I would like to use the hg log command much like I use the git log --describe --all command which I'm more familiar with. 理想情况下,我希望使用hg log命令,就像使用我更熟悉的git log --describe --all命令一样。

Is there a template for the hg log command that is equivalent to git log --describe ? 是否有与git log --describe等效的hg log命令模板

Note: I'm already aware of using hg out <remote> to show me what set of commits is not available on the remote I'm interested in, but I was hoping for something a little more visual. 注意:我已经知道使用hg out <remote>向我展示我感兴趣的远程设备上没有可用的提交集,但是我希望有一些视觉效果。

在默认样式下,无需对标准HG工作流(假设在另一个扩展名remotenames中 )进行重大更改,就可以将Remote Branches Extension添加到Mercurial中。

I have pulled from both remotes and would like to know which commits/branches came from the remote called default and which commits/branches came from the remote called upstream . 我从这两个远程服务器都退出了,想知道哪些提交/分支来自远程服务器,称为default ,哪些提交/分支来自远程服务器,称为upstream How do I achieve this in Hg? 如何在汞中实现这一目标?

In general, you can't. 一般来说,您不能。 (But see below, and Lazy Badger's suggested extension .) (但请参见下文,以及Lazy Badger建议的扩展名 。)

Git doesn't actually do this either. Git实际上也没有这样做。 Nonetheless, you can, as you said: 尽管如此,正如您所说,您可以:

... use the git log --describe --all command ... ...使用git log --describe --all命令...

This does not tell you who delivered the commits to you . 这不会告诉您谁将提交内容交付给您 Instead, it tells you which of your references is "closest" to the to-be-described commit ("closest" being defined in a vague handwave-y manner). 相反,它告诉您引用中的哪个 “最接近”到将要描述的提交(“最接近”是以模糊的“手摇”方式定义的)。 What Git does, that Mercurial doesn't, is to create, in your repository, specific references—remote-tracking names like remote1/branch and remote2/branch —that remember which commit was identified by the name branch on remote1 and remote2 respectively. Mercurial没做的Git所做的是在您的存储库中创建特定的引用(例如remote1/branchremote2/branch的远程跟踪名称),这些引用记住哪个提交分别由remote1和remote2上的名称branch标识。

Provided that precisely one of the two remotes has those commits in the first place, only one such reference can be "closest". 如果两个遥控器中的一个恰好具有这些提交,则只有一个这样的引用是“最近的”。 Git will choose that one, and from that, you can infer who has the commits and who does not. Git会选择一个,然后您可以推断出谁拥有提交,谁没有提交。 It fails, or can fail, if both remotes have the commits: you get an arbitrary reference (which may suffice anyway depending on your underlying goal). 如果两个遥控器都具有提交,则它将失败,或者可能失败:您将获得一个任意引用(无论如何,这都可以满足您的基本目标)。

Now, you can do something . 现在,您可以 做点什么 Specifically, the issue in this case is that Mercurial's branch names are global, and commits are permanently glued to the branch on which they were made. 具体而言,这种情况下的问题在于Mercurial的分支名称是全局的,并且提交永久粘贴到创建它们的分支上。 If you connect to remote1 and receive some commits, they have whatever hash ID and branch name they have, and your Mercurial stores them in your repository under that same hash ID and using that same name—and now Mercurial (like Git) forgets the source, because those are now your commits. 如果您连接到remote1并收到一些提交,它们将具有其任何哈希ID和分支名称,并且您的Mercurial将它们以相同的哈希ID和相同的名称存储在您的存储库中,现在Mercurial(如Git)会忘记源,因为这些现在是您的提交。

But you do know that whatever commits just came in (if any) came from remote1, not remote2. 但是您确实知道,刚刚传入的任何提交(如果有)都来自remote1,而不是remote2。 Moreover, if any commits did come in, they will have increased the local revision ID number ( -r -n tip ). 此外,如果确实提交任何提交,则它们将增加本地修订ID号( -r -n tip )。 You can save that new number—or even the entire span—somewhere. 您可以在某个位置保存该新数字,甚至可以保存整个跨度。 All of those commits in that span, "old tip + 1" to "new tip" inclusive, came from remote1. 在此范围内的所有提交(包括“旧提示+ 1”到“新提示”)均来自remote1。

Repeat this for remote2: any new commits that arrive came from them. 对remote2重复此操作:到达的所有新提交都来自它们。

(There is another option, but it's drastic: you can use the Convert extension to change the branch names of commits as they come in. If you do this, though, you are stuck with those commits being on the other branch: you would have to copy, ie, graft or rebase, the commits to move them to their original branches later, if you want that. There are additional, and better, extensions, but unlike Convert, they are not distributed with Mercurial.) (还有另一种选择,但这太过激烈了:您可以使用Convert扩展名在提交时更改提交的分支名称。但是,如果这样做,则将这些提交卡在另一个分支上:复制(即嫁接或变基)提交,以便以后将它们移至其原始分支。还有其他更好的扩展,但与Convert不同,它们不与Mercurial一起分发。)

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

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