简体   繁体   English

如何将所有合并的远程 git 分支转换为标签? (创建标签,删除分支)

[英]How to convert all merged remote git branches to tags? (create tags, delete branches)

(在我使用 giltab 的delete merged branches功能之前(请参阅https://docs.gitlab.com/ee/user/project/repository/branches/#delete-merged-branches )-我想标记它们-以防万一将来需要参考它们。)

(on linux:) (在Linux上:)

how to tag all merged remote git branches in bulk如何批量标记所有合并的远程git分支

git branch --remotes --merged |
grep --invert-match --perl-regexp "^  origin/(HEAD ->|master$)" |
sed "s#^  origin/##g" |
xargs -I {} \
git push origin origin/{}:refs/tags/merged/{}
  • git branch - list all remote merged branches git branch - 列出所有远程合并的分支
  • grep - exclude head, master from the list grep - 从列表中排除头部,主人
  • sed - remove the origin/ prefix from branch names sed - 从分支名称中删除origin/前缀
  • xargs -I execute a following command one time for each line got from previous command (replacing every occurrence of {} with the name of a branch) xargs -I对从前一个命令获得的每一行执行一次以下命令(用分支名称替换每次出现的{}
  • git push - tag remote branch with merged/<branch-name> tag git push - 使用merged/<branch-name>标签标记远程分支

after that, remote merged branches may be deleted since they're no longer needed anymore.之后,远程合并的分支可能会被删除,因为不再需要它们。

how to update local copies of remote tags & branches after the remote ones were added/deleted添加/删除远程标签和分支后,如何更新远程标签和分支的本地副本

git fetch --tags --prune
  • --prune will delete local copies of remote branches that no more exist in remote repo --prune将删除远程--prune中不再存在的远程分支的本地副本
  • --tags 'll fetch tags created in previous section --tags将获取在上一节中创建的标签

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM