【发布时间】:2011-10-03 17:38:22
【问题描述】:
我即将完成将“哑快照”转换为 git 的繁琐过程。这个过程进展顺利(感谢this rename process),但现在我意识到我创建的一些分支不值得branch,而是tag。
由于一切仍然是本地的(从未推送到存储库),我发现this question(和相关的答案)比我喜欢的要麻烦一些,所以我想知道我是否可以通过一些简单的“convert-from”来走捷径-branch-to-tag”命令?
有这么简单的命令可以将分支转为标签吗?
(我知道我可以保持原样,但我真的很喜欢 gitk 突出显示标签的方式,帮助我轻松识别它们)。
更新:感谢@Andy 在下面的回答,我设法想出了一个 shell 脚本,它可以方便、轻松地完成这一切。我分享这个脚本是为了所有人的利益,并特别感谢这个伟大的社区,他们让我从 CVS 迁移到 git 成为可能:
#!/bin/sh
BRANCHNAME=$1
TAGNAME=$2
echo "Request to convert the branch ${BRANCHNAME} to a tag with the same name accepted."
echo "Processing..."
echo " "
git show-ref --verify --quiet refs/heads/${BRANCHNAME}
# $? == 0 means local branch with <branch-name> exists.
if [ $? == 0 ]; then
git checkout ${BRANCHNAME}
git tag ${BRANCHNAME}
git checkout master
git branch ${BRANCHNAME} -d
echo " "
echo "Updated list branches, sorted chronologically: "
echo "---------------------------------------------- "
git log --no-walk --date-order --oneline --decorate $(git rev-list --branches --no-walk) | cut -d "(" -f 2 | cut -d ")" -f 1
else
echo "Sorry. The branch ${BRANCHNAME} does NOT seem to exist. Exiting."
fi
【问题讨论】:
-
“有没有简单的命令...” - Git 中几乎没有什么是简单的或与基本工作流程相匹配的,因此很可能很容易回答:否。 simple 之后的一切都无所谓 :)
标签: git git-branch git-tag