有一个简单的命令将分支转换为标签吗? [英] Is there a simple command to convert a branch to a tag?

查看:110
本文介绍了有一个简单的命令将分支转换为标签吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我即将完成将笨拙快照转换为git的繁琐过程。这个过程一直很顺利(感谢这个重命名过程),但现在我意识到我创建的一些分支不符合分支,而是一个标签



因为一切仍然是本地的(从未推送到存储库),我发现这个问题(和相关的答案)比我更喜欢的麻烦,所以我想知道我是否可以通过一些简单的convert-from-branch-to-tag命令来获取快捷方式吗?

是否有如此简单的命令将分支转换为标签? / p>

(我知道我可以保持原样,但我真的很喜欢 gitk 突出显示标签的方式,帮助我轻松识别它们)。



更新:感谢@ Andy的回答bel我设法想出了一个shell脚本,它可以方便而且无痛地执行。我为所有人的利益分享了这个脚本,特别感谢这个伟大的社区,他为CVS提供了可能:

 #!/ bin / sh 

BRANCHNAME = $ 1
TAGNAME = $ 2

echo请求将分支$ {BRANCHNAME}转换为标签同一个名字被接受。
echoProcessing ...
echo

git show-ref --verify --quiet refs / heads / $ {BRANCHNAME}
#$ ? == 0表示带有<分支名称>的本地分支存在。

if [$? == 0];然后
git checkout $ {BRANCHNAME}
git tag $ {BRANCHNAME}
git checkout master
git branch $ {BRANCHNAME} -d
echo
回声更新列表分支,按时间顺序排序:
回声--------------------------------- -------------
git log - 不走路 - 日期顺序 - 线路 - 装饰$(git rev-list --branches - 不走)| cut -d(-f 2 | cut -d)-f 1
else
echo对不起。分支$ {BRANCHNAME}似乎不存在。退出。
fi


解决方案

分支机构? (你链接的帖子,在这些分支上似乎没有发展)
如果没有开发,你可以:


  1. 检查分支 git checkout branchName

  2. 使用标记标签tag tag

  3. 切换回master git checkout master

  4. 最后, code> git branch branchName -d 。

如果有开发,也可以这样做在分支上,但是你需要使用 -D 而不是 -d 。我不是一个git专业版,所以不知道这是不是一个可接受的离开分支。


I am about to complete a tedious process of converting "dumb snapshots" to git. This process has been going very well (thanks to this rename process), but now I realized that some of the branches that I created, do not merit a branch but rather a tag.

Since everything is still local (never pushed to a repository), I found this question (and associated answer) somewhat more cumbersome than I prefer, so I was wondering whether I can take a shortcut via some simple "convert-from-branch-to-tag" command?

Is there such a simple command to convert a branch to a tag?

(I know I can just leave it as is, but I really like the way gitk highlights tags, helping me easily identify them).

UPDATE: Thanks to @Andy's answer below, I managed to come up with a shell script that does it all conveniently and painlessly. I am sharing this script for the benefit of all and as special thanks to this great community who made moving for CVS to git possible for me:

#!/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

解决方案

Was there separate development on these branches? (the post you linked to, doesn't appear to have development on those branches) If there was no development, you could:

  1. Checkout the branch git checkout branchName.
  2. Tag it with git tag tagName.
  3. Switch back to master git checkout master.
  4. Finally, delete original branch with git branch branchName -d.

This can also be done if there was development on the branch, but you will need to use -D instead of -d. I'm not a git pro though, so not sure if that is an "acceptable" way to leave a branch.

这篇关于有一个简单的命令将分支转换为标签吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆