Tortoise HG - 在提交时添加标签

发布于 2024-10-08 20:45:46 字数 57 浏览 0 评论 0原文

目前,我只知道如何在提交后添加标签。这意味着获得仅包含该标签的第二次提交。是否可以在提交时添加标签?

At the moment, I only know how to add a tag after a commit. This means that a get a second commit that just contains the tag. Is it possible to add a tag on commit?

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

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

发布评论

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

评论(4

泪是无色的血 2024-10-15 20:45:46

否,因为标签是存储库根目录下的 .hgtags 文件中的一个条目,包含变更集 ID 和标签名称,并且该文件本身处于修订控制之下。在创建变更集之前,变更集 ID 是未知的,因此标记会创建另一个变更集来签入记录该变更集标签的 .hgtags 文件。

No, because a tag is an entry in the .hgtags file at the root of your repository containing the changeset id and the tag name, and this file itself is under revision control. The changeset id isn't known until the changeset is created, so tagging creates another changeset to check in the .hgtags file recording the tag for that changeset.

○愚か者の日 2024-10-15 20:45:46

根据 Mercurial wiki 的说法,这是不可能的。正如马克所说。
https://www.mercurial-scm.org/wiki/Tag

但是,我只是想知道。为什么 Mercurial 不完全忽略 .hgtags 文件?就像它忽略 .hg/ 文件夹一样。
因此,mercurial 在每次生成变更集 ID 时不会包含 .hgtags。

如果 .hgtags、.hgignores 等位于 .hg/ 内,那就太好了

According to mercurial wiki, it is impossible. Just like Mark said.
https://www.mercurial-scm.org/wiki/Tag

But then, i just wondering. Why not mercurial ignoring the .hgtags file altogether ? just like it ignores .hg/ folder.
So mercurial won't include .hgtags everytime it's generating a changeset ID.

Would be great if .hgtags, .hgignores, etc is resides inside .hg/

你如我软肋 2024-10-15 20:45:46

在我看来,Hg 标记系统有点混乱,因为创建标记会更改历史记录,即使没有项目文件发生更改,也需要合并和提交。标记会很快给历史图带来负担。

我使用了 SVN 标记,它是在单独的分支上完成的,其优点是不更改工作分支历史记录。此外,可以从任何分支进行标记,因为 Hg 从所有分支头部的 .hgtags 文件中获取标记。

下面的小脚本创建一个分支“标记”并将标签放入其中。它将当前分支合并到“标记”分支中,因此很容易看到变更集标记是从哪里完成的(它特别避免了切换分支时的长时间刷新)。

它可能可以改进,但它适合我的需要。

我强烈建议在测试此脚本之前克隆您的项目,以防它的行为不符合您的预期!

#!/bin/bash

function echo_red()
{
  echo -n -e "\e[01;31m"
  echo -n "$1"
  echo -e "\e[00m"
}
export -f echo_red

# Display the help and exit
function show_help {
    echo "Usage: $0 [hg_tag_options ...]"
    echo "    tags a version (current if not specified) in the 'tagging' branch."
    echo "    Options are the 'hg tag' ones, plus"
    echo "        -?, -h, --help  Show (this) help"
    exit 1
}

#  Parse the command-line arguments
function parse_args {
    for arg in "${commandline_args[@]}"
    do
        case "$arg" in #(
            '-?' | -h | --help )
                                show_help
                                ;;
        esac
    done
}

commandline_args=("$@") 
if [ "$commandline_args" = "" ]
then
    show_help
fi
parse_args

VER=`hg id | sed 's#\([0-9a-z]*\).*#\1#g'`
BRANCH=`hg branch`

# Check for clean directory
TEST=`hg st -S -q`
if [ "$TEST" != "" ]
then
    echo_red "Directory contains unresolved files !"
    exit 1
fi

hg update --check >/dev/null
if [ $? -ne 0 ]
then
    echo_red "Directory contains unresolved files !"
    exit 1
fi

# Switch to tagging branch
hg update tagging >/dev/null
if [ $? -ne 0 ]
then
    echo "Creating new 'tagging' branch."
    hg update default >/dev/null
    hg branch tagging
fi

# Merge if changes detected
TEST=`hg diff -r $VER -X .hgtags --stat`
if [ "$TEST" != "" ]
then
    #take only the 'tagging' version of hgtags
    cp .hgtags .hgtags.bak
    hg merge -r $VER --tool internal:other >/dev/null
    rm .hgtags
    mv .hgtags.bak .hgtags
    hg commit -m Merged
fi

# Tag and Switch back to original
hg tag -r $VER $@
hg update $BRANCH >/dev/null
hg update $VER >/dev/null

用法示例:

hg_tag.sh [-f] [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] test_v1_5

For my point of view, Hg tagging system is a bit messy because creating a tag changes the history and needs merging and committing even if no project file has changed. Tagging can burden a history graph very quickly.

I was used of SVN tagging which was done on a separate branch, which has the advantage not to change working branch history. Moreover, tagging can be done from any branch, because Hg takes tags from the .hgtags files on the heads of all branches.

The little script below creates a branch "tagging" and puts tags in it. It merges the current branch in "tagging" branch, so it's easy to see the changeset tag was done from (it especially avoids long refreshes when switching branch).

It can probably be improved, but it suits my needs.

I strongly recommend making a clone of your project before testing this script, in case it does not behave as you expect!

#!/bin/bash

function echo_red()
{
  echo -n -e "\e[01;31m"
  echo -n "$1"
  echo -e "\e[00m"
}
export -f echo_red

# Display the help and exit
function show_help {
    echo "Usage: $0 [hg_tag_options ...]"
    echo "    tags a version (current if not specified) in the 'tagging' branch."
    echo "    Options are the 'hg tag' ones, plus"
    echo "        -?, -h, --help  Show (this) help"
    exit 1
}

#  Parse the command-line arguments
function parse_args {
    for arg in "${commandline_args[@]}"
    do
        case "$arg" in #(
            '-?' | -h | --help )
                                show_help
                                ;;
        esac
    done
}

commandline_args=("$@") 
if [ "$commandline_args" = "" ]
then
    show_help
fi
parse_args

VER=`hg id | sed 's#\([0-9a-z]*\).*#\1#g'`
BRANCH=`hg branch`

# Check for clean directory
TEST=`hg st -S -q`
if [ "$TEST" != "" ]
then
    echo_red "Directory contains unresolved files !"
    exit 1
fi

hg update --check >/dev/null
if [ $? -ne 0 ]
then
    echo_red "Directory contains unresolved files !"
    exit 1
fi

# Switch to tagging branch
hg update tagging >/dev/null
if [ $? -ne 0 ]
then
    echo "Creating new 'tagging' branch."
    hg update default >/dev/null
    hg branch tagging
fi

# Merge if changes detected
TEST=`hg diff -r $VER -X .hgtags --stat`
if [ "$TEST" != "" ]
then
    #take only the 'tagging' version of hgtags
    cp .hgtags .hgtags.bak
    hg merge -r $VER --tool internal:other >/dev/null
    rm .hgtags
    mv .hgtags.bak .hgtags
    hg commit -m Merged
fi

# Tag and Switch back to original
hg tag -r $VER $@
hg update $BRANCH >/dev/null
hg update $VER >/dev/null

Example Usage:

hg_tag.sh [-f] [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] test_v1_5
梓梦 2024-10-15 20:45:46

不确定这是否是您正在寻找的内容,但您可以将标记移动到不同的变更集。

hg com -m "moving tag to this changeset"
hg tag 0.1 -f
hg push

Not sure if this is what you are looking for, but you can move the tag to a different changeset.

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