Search code examples
gitbashcontinuous-integrationmicroservicesmonorepo

ci/cd independent microservices in monorepo with git bash


Using Bash and git, how do I get a collection of directories containing files that differ from that last time the branch was merged into master?

Even better would be a collection of changed that match a pattern such as containing a particular file name , i.e. building a collection of changed directories containing package.json and a different collection of changed containing requirements.txt.


Solution

  • You can use git merge-base to get the last merge:

    git diff --name-only $(git merge-base --fork-point master myBranch)..myBranch
    

    On the fork-point part, see this answer.

    From there, you can grep by pattern to filter out the result.

    As torek adds in the comments, if fork-point is not needed, and using a pathspec

    git diff --name-only master...myBranch -- requitements.txt
    

    See "What are the differences between double-dot "..." and triple-dot "..." in Git diff commit ranges?"

    http://mythic-beasts.com/~mark/git-diff-help.png