Win*_*Win 27 git git-tag git-branch
我即将完成将"哑快照"转换为git的繁琐过程.这个过程一直很顺利(感谢这个重命名过程),但现在我意识到我创建的一些分支不值得branch,而是一个tag.
由于一切都仍然是本地的(从未被推送到存储库),我发现这个问题(和相关的答案)比我更喜欢有点麻烦,所以我想知道我是否可以通过一些简单的"转换为分支"来获取快捷方式-tag"命令?
是否有这么简单的命令将分支转换为标签?
(我知道我可以保留它原样,但我真的很喜欢gitk突出标签的方式,帮助我轻松识别它们).
更新:感谢@ Andy在下面的回答,我设法提出了一个shell脚本,可以方便,轻松地完成所有操作.为了所有人的利益,我正在分享这个脚本,特别感谢这个伟大的社区,他为我提供了CVS to 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
Run Code Online (Sandbox Code Playgroud)
kau*_*ppi 26
给出的答案基本上是正确的.
由于标签和分支只是对象的名称,因此有一种更简单的方法,而不会触及当前的工作区域:
git tag <name_for_tag> refs/heads/<branch_name> # or just git tag <name_for_tag> <branch_name>
git branch -d <branch_name>
Run Code Online (Sandbox Code Playgroud)
甚至可以在不触及本地存储库的情况下将其用于远程服务器:
git push origin origin/<branch_name>:refs/tags/<tag_name>
git push origin :refs/heads/<branch_name>
Run Code Online (Sandbox Code Playgroud)
And*_*ndy 17
这些分支机构是否有单独的发展?(您链接到的帖子,似乎没有在这些分支上进行开发)如果没有开发,您可以:
git checkout branchName.git tag tagName. git checkout master.git branch branchName -d.如果分支上有开发,也可以这样做,但您需要使用-D而不是-d.我不是一个git pro,所以不确定这是否是一个"可接受的"离开分支的方式.
| 归档时间: |
|
| 查看次数: |
5807 次 |
| 最近记录: |