首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >什么git命令可以用来检查何时创建了远程分支?

什么git命令可以用来检查何时创建了远程分支?
EN

DevOps用户
提问于 2018-02-09 21:12:16
回答 1查看 10K关注 0票数 5

Git在工作中使用。树枝的数量在不断增加。其目的是去除超过X周的分支。

尝试1

运行git branch -h可能会指示在创建分支时要运行什么来检查。

代码语言:javascript
复制
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

尝试2

找到了这个post https://stackoverflow.com/questions/3184555/cleaning-up-old-remote-git-branches,但这不是一个选项,因为它在不检查年龄的情况下删除分支。

EN

回答 1

DevOps用户

回答已采纳

发布于 2018-02-09 23:18:02

注意:这个答案显示了如何找到很久以前就已经更新过*的分支,而不是很久以前创建的分支*(也就是某个父分支的拼接)。我相信这是OP真正想要的(与他为这个问题选择的标题相反),因为这将导致很好的删除候选人。

你必须记住,git中的一个分支并不是“物理的”。顾名思义,它只是.git/refs中的一个简单文本文件,它只有其文件名(即分支名称)和提示/头提交的哈希。它没有日期信息或其他任何信息。

所以git branch不会在这里帮助你。

具有与其关联的日期的对象类型在git中被提交。所以你必须列出提交。这是用git log完成的。

因此,一个有效的命令是:

代码语言:javascript
复制
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:显示所有相关的标记和分支名称,以防万一

这将给你所有的分支机构负责人,比你给定的日期更老。

票数 7
EN
页面原文内容由DevOps提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://devops.stackexchange.com/questions/3321

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档