Git在工作中使用。树枝的数量在不断增加。其目的是去除超过X周的分支。
运行git branch -h可能会指示在创建分支时要运行什么来检查。
user@localhost $ git branch -h
usage: git branch [<options>] [-r | -a] [--merged | --no-merged]
or: git branch [<options>] [-l] [-f] <branch-name> [<start-point>]
or: git branch [<options>] [-r] (-d | -D) <branch-name>...
or: git branch [<options>] (-m | -M) [<old-branch>] <new-branch>
or: git branch [<options>] [-r | -a] [--points-at]
Generic options
-v, --verbose show hash and subject, give twice for upstream branch
-q, --quiet suppress informational messages
-t, --track set up tracking mode (see git-pull(1))
--set-upstream change upstream info
-u, --set-upstream-to <upstream>
change the upstream info
--unset-upstream Unset the upstream info
--color[=<when>] use colored output
-r, --remotes act on remote-tracking branches
--contains <commit> print only branches that contain the commit
--abbrev[=<n>] use <n> digits to display SHA-1s
Specific git-branch actions:
-a, --all list both remote-tracking and local branches
-d, --delete delete fully merged branch
-D delete branch (even if not merged)
-m, --move move/rename a branch and its reflog
-M move/rename a branch, even if target exists
--list list branch names
-l, --create-reflog create the branch's reflog
--edit-description edit the description for the branch
-f, --force force creation, move/rename, deletion
--merged <commit> print only branches that are merged
--no-merged <commit> print only branches that are not merged
--column[=<style>] list branches in columns
--sort <key> field name to sort on
--points-at <object> print only branches of the object找到了这个post https://stackoverflow.com/questions/3184555/cleaning-up-old-remote-git-branches,但这不是一个选项,因为它在不检查年龄的情况下删除分支。
发布于 2018-02-09 23:18:02
注意:这个答案显示了如何找到很久以前就已经更新过*的分支,而不是很久以前创建的分支*(也就是某个父分支的拼接)。我相信这是OP真正想要的(与他为这个问题选择的标题相反),因为这将导致很好的删除候选人。
你必须记住,git中的一个分支并不是“物理的”。顾名思义,它只是.git/refs中的一个简单文本文件,它只有其文件名(即分支名称)和提示/头提交的哈希。它没有日期信息或其他任何信息。
所以git branch不会在这里帮助你。
具有与其关联的日期的对象类型在git中被提交。所以你必须列出提交。这是用git log完成的。
因此,一个有效的命令是:
git log --remotes --before 2018-01-01 --no-walk --decorate您可以阅读https://www.git-scm.com/docs/git-log的详细信息,但简而言之,它意味着
--remotes:从任意和所有远程分支开始(以--branches代替本地分支)--before ...:只有list比给定的日期更早提交--no-walk:只列出每个分支的第一次提交,不要追溯历史--decorate:显示所有相关的标记和分支名称,以防万一这将给你所有的分支机构负责人,比你给定的日期更老。
https://devops.stackexchange.com/questions/3321
复制相似问题