如何更改默认分支以推送到 Mercurial 中?

发布于 2024-08-31 15:19:19 字数 657 浏览 2 评论 0原文

我喜欢在 Mercurial 中创建命名分支来处理可能需要一段时间编码的功能,因此当我推送时,我会执行 hg push -r default 以确保我只将更改推送到默认分支。然而,每次执行推送或传出命令时都必须记住 -r default ,这很痛苦。

所以我尝试通过将此配置添加到我的 ~/.hgrc 来解决此问题:

[defaults]
push = push -r default
outgoing = outgoing -r default

问题是,这些配置行并不是真正的默认值,它们是别名。它们按预期工作,直到我尝试执行 hg Push -r。我设置的“默认”只是删除了我传入的修订版。(我看到 默认值已弃用,但别名也有同样的问题)。

我尝试环顾四周,但找不到任何可以让我设置默认分支来推送并允许我在必要时覆盖它的东西。有人知道我还能做些什么吗?

ps:我确实意识到我可以为每个分支拥有单独的克隆,但我宁愿不这样做。必须切换目录很烦人,特别是当您共享配置或编辑器工作区时。

I like creating named branches in Mercurial to deal with features that might take a while to code, so when I push I do a hg push -r default to ensure I'm only pushing changes to the default branch. However, it is a pain to have to remember -r default every time I do do a push or outgoing command.

So I tried fix this by adding this config to my ~/.hgrc:

[defaults]
push = push -r default
outgoing = outgoing -r default

The problem is, those config lines are not really defaults, they are aliases. They work as intended until I try to do a hg push -r <some revision>. And the "default" I've setup just obliterates the revision I passed in. (I see that defaults are deprecated, but aliases have the same problem).

I tried looking around, but I can't find anything that will allow me to set a default branch to push AND allow me to override it when necessary. Anyone know of something else I could do?

ps: I do realize that I could have separate clones for each branch, but I would rather not do that. It's annoying to have to switch directories, particularly when you have shared configuration or editor workspaces.

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

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

发布评论

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

评论(3

计㈡愣 2024-09-07 15:19:19

我不认为你可以用纯水银来做到这一点,除非有一个只有那个分支的克隆(我正要建议,直到你说这不是你的那杯茶)。如果它真的让你很烦恼,你可以创建一个小包装脚本,例如:

#!/bin/sh
HG=/full/path/to/hg # executable
if echo $* | grep -P -q -- 'push.*\s-r($|\s)' ; then
   $HG $*
else
   $HG $* -r default
fi

将其命名为“hg”并将其放在路径的前面。

I don't think you can do it with pure mercurial, short of having a clone with only that branch in it (which I was was about to suggest until you said it wasn't your cup of tea). If it's really killing you you can create a tiny wrapper script like:

#!/bin/sh
HG=/full/path/to/hg # executable
if echo $* | grep -P -q -- 'push.*\s-r($|\s)' ; then
   $HG $*
else
   $HG $* -r default
fi

name it 'hg' and put it earlier in your path.

天冷不及心凉 2024-09-07 15:19:19

您可能正在使用 Tortoise HG 吗?完全恢复到显式分支名称将导致 Tortoise HG 记住您在后续提交期间正在处理的分支。我不确定它从什么元数据中收集这些信息。

hg up -r {branchname}

例如

hg up -r dev 

Are you using Tortoise HG perhaps? Doing a full revert to an explicit branch name will cause Tortoise HG to remember the branch you're working on during subsequent commits. I'm not sure what metadata it gleans this from.

hg up -r {branchname}

e.g.

hg up -r dev 
八巷 2024-09-07 15:19:19

由于通常您应该将变更集推送到您正在工作的当前分支中,因此我修改了 ry4an-brase 所做的上述答案,以带有通知的方式推送当前分支。

#!/bin/sh
HG=/usr/bin/hg # executable

if echo $* | grep -P -q -- 'push\s*
 ; then
    printf "\033[1;31mChanged to: hg push -r .\033[0m\n"
    $HG $* -r .
else
    $HG $*
fi

Since normally you should push changesets in the current branch you are working, I modified the above answer made by ry4an-brase, to push current branch with a notice.

#!/bin/sh
HG=/usr/bin/hg # executable

if echo $* | grep -P -q -- 'push\s*
 ; then
    printf "\033[1;31mChanged to: hg push -r .\033[0m\n"
    $HG $* -r .
else
    $HG $*
fi
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文