【发布时间】:2010-12-22 03:18:49
【问题描述】:
目前,我只知道如何在提交后添加标签。这意味着获得仅包含该标记的第二次提交。是否可以在提交时添加标签?
【问题讨论】:
标签: mercurial tortoisehg
目前,我只知道如何在提交后添加标签。这意味着获得仅包含该标记的第二次提交。是否可以在提交时添加标签?
【问题讨论】:
标签: mercurial tortoisehg
不,因为标签是存储库根目录下 .hgtags 文件中的一个条目,其中包含变更集 ID 和标签名称,并且该文件本身处于修订控制之下。在创建变更集之前,变更集 ID 是未知的,因此标记会创建另一个变更集以签入记录该变更集标签的 .hgtags 文件。
【讨论】:
根据 mercurial wiki,这是不可能的。就像马克说的那样。 https://www.mercurial-scm.org/wiki/Tag
但是,我只是想知道。为什么不完全忽略 .hgtags 文件?就像它忽略 .hg/ 文件夹一样。 所以 mercurial 不会在每次生成变更集 ID 时都包含 .hgtags。
如果 .hgtags、.hgignores 等位于 .hg/ 内,那就太好了
【讨论】:
在我看来,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
【讨论】:
不确定这是否是您要查找的内容,但您可以将标签移动到不同的变更集。
hg com -m "moving tag to this changeset"
hg tag 0.1 -f
hg push
【讨论】: