【问题标题】:List git repositories with unpushed changes列出未推送更改的 git 存储库
【发布时间】:2014-05-09 06:19:31
【问题描述】:

我正在重新安装我的操作系统。我的计算机上有数千个存储库。我有一种感觉,我在一些未提交和/或推送的代码库中进行了一些更改。

从我的 Debian PC 上的 bash shell 中,找到尚未提交/推送到远程的更改列表并决定是否要保留更改的最佳方法是什么?

【问题讨论】:

  • 未提交的更改呢?
  • 抱歉这个愚蠢的评论,但是你好 Greg。我第一次意识到两个人可以有相同的 SO 名称。

标签: git bash debian debian-based


【解决方案1】:

您可能喜欢 Ferry Boender 的项目 multi-git-status。

https://github.com/fboender/multi-git-status.
“在多个 Git 存储库中显示未提交、未跟踪和未推送的更改。”

【讨论】:

    【解决方案2】:

    我假设找到每个 repo 并在每个 repo 中运行 git status 足以满足您的需求。在这种情况下,以下可能是您的起点:

    find / -name "*.git" -type d -print0 | xargs -0 -L 1 -i% bash -c "cd %/..; pwd; git status -s -uno"
    

    find 遍历您的文件系统,从/ 开始(您可能希望将其限制为~),搜索.git 目录。输出(以 null 分隔以处理有趣的文件名)通过管道传输到 xargs,其中 cds 到每个 repo,打印 pwd 和短格式 git-status,而不列出未跟踪的文件。

    【讨论】:

      【解决方案3】:

      上一个答案找到未提交的,但不是未推送的提交。

      这将找到两个:

      find / -name "*.git" -type d -print0 | xargs -0 -L 1 -i% bash -c "cd %/..; pwd; git status -s -uno; git cherry -v 2>/dev/null"

      git cherry 显示未推送更改的 SHA1; -v 添加提交注释;并且错误重定向会抑制缺少上游的 repos 的嘈杂输出。

      【讨论】:

      • 在 Mac 上(使用 zsh)小写 -i 抛出 "xargs: 非法选项 -- i";使用资本我工作:xargs -0 -L 1 -I% bash -c
      【解决方案4】:

      确保检查所有分支

      未推送的更改可以存在于检出分支以外的分支中。每个分支也可以有多个上游。

      关注相关信息

      这种方法借鉴了其他答案,这些答案是非常有用的起点,并省略了一些细节。

      find / -name "*.git" -type d -print0 | xargs -0 -L 1 -I% sh -c "cd %/..; pwd; git status -suno; git branch -vvv 2>/dev/null"
      

      上面的单行

      • 列出所有分支,用星号标记已签出的分支
      • 说明何时分离 repo HEAD
      • 显示带有未提交更改的跟踪文件
      • 区分哪些分支有上游,哪些没有
      • 计算每个分支在其上游之前/之后的提交次数
      • 在每个分支上提供最新的 sha 和提交消息

      与其他解决方案一样,它还列出了每个 repo 的路径。与其他解决方案不同,它不会在签出分支上列出对未推送提交的引用列表。

      示例输出

      /dir-with-repo-1
          main  d96c7fcd [origin/main: behind 3] update abcd
        * staging f938e4aa [origin/staging: ahead 2, behind 6] tweak workspace layout
      /dir-with-repo-2
        * dev   8b9cec2b [origin/dev] Merge branch 'feature/35-featurename' into 'dev'
          main  b96d6fcd [origin/main: behind 4] update efgh
      /dir-with-repo-3
        * hotfix  239f95dc [origin/hotfix] update ijkl
          main    4c92eaa7 [origin/main: behind 7] update klmn
      /dir-with-repo-4
        M composer.json
        M composer.lock
        * main 0d2050c add opqr
      /dir-with-repo-5
        * (HEAD detached at d3286d57) d3286d57 fix(FunctionComment): Add support for hijk
          1.2.3                       d3286d57 [origin/1.2.3] Add support for hijk
      

      【讨论】:

        猜你喜欢
        • 2013-08-28
        • 2016-06-27
        • 1970-01-01
        • 2016-10-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多