3

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Tom
  • 981
  • 11
  • 24

1 Answers1

1

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

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Note that if you don't need the `--fork-point` behavior, you can use the special semantics of triple-dot in `git diff`: `git diff --name-only master...myBranch`. (If your patterns are simple glob patterns you can do them in the `git diff` step as well, as pathspecs.) – torek Oct 16 '16 at 08:22
  • @torek good point. I have included and illustrated it in the answer for more visibility. – VonC Oct 16 '16 at 09:31
  • fork-pont is needed in this case. Thank you both for the prefect answer to this question. – Tom Oct 17 '16 at 22:12