获取受git monorepo最近提交影响的所有第一级目录的列表 [英] get a list of all 1st level directories impacted by recent commits for a git monorepo

查看:121
本文介绍了获取受git monorepo最近提交影响的所有第一级目录的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用monorepos,并且尝试检索列表中自给定提交以来受影响的所有1级子文件夹.

I am currently playing with monorepos and I am trying to retrieve a list all 1 level subfolders in the repo which are impacted since a given commit.

到目前为止,我可以检索受git diff --name-only $COMMIT_ID..head

So far I can retrieve all the files impacted using git diff --name-only $COMMIT_ID..head

使用git diff --name-only $COMMIT_ID..head | xargs -L1 dirname我设法只获取文件夹名称.

Using git diff --name-only $COMMIT_ID..head | xargs -L1 dirname I manage to get only the folder names.

要删除所有重复的内容,我将sort | uniq添加到了组合中:git diff --name-only $COMMIT_ID..head | xargs -L1 dirname | sort | uniq

To remove all the duplicates I added sort | uniq to the mix: git diff --name-only $COMMIT_ID..head | xargs -L1 dirname | sort | uniq

我现在所要做的就是确保仅检索第一级文件夹,即project1而不是project1/srcproject1/lib

All I need now is to ensure I only retrieve the first level folders i.e. project1 not project1/src and project1/lib

我尝试了几种选择,但到目前为止,我还没有设法将其保持为一体.

I have tried a few options but I have not managed to keep it as a one liner so far.

推荐答案

以下是awk

git diff --name-only $COMMIT_ID | awk -F'/' 'NF!=1{print $1}' | sort -u

  • -F'/'将定界符字段设置为斜杠/
  • NF!=1{print $1}如果行中包含斜线/,则会打印出第一级,即第一级目录名称,这会滤除第一级中存在的文件

    • -F'/' sets the delimiter field to slash /
    • NF!=1{print $1} prints out the first field which is the first level directory name if the line contain slashes /, this filters out files that exists in the first level

      readme.md          NF==1
      project1/file      NF==2
      project2/src/file  NF==3
      

    • sort -u结合了排序和唯一性

    • sort -u combined sort and unique

      这篇关于获取受git monorepo最近提交影响的所有第一级目录的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆