79386818

Date: 2025-01-25 13:45:10
Score: 2.5
Natty:
Report link

Since I want to use it often, I made @jthill's answer into an alias.

Add the alias with

git config --global alias.branch-diff "!f(){ git diff $(git merge-base $1 $2) $2 "${@:3}"; }; f"

With syntax git branch-diff <arg1> <arg2> <more args>. The 1st argument represents the master branch, which the branch in the 2nd argument split off at some point. Further arguments are passed to the diff.

Usage:

  1. What files did i change in branch?
git branch-diff master other-branch --name-only

The alias expands this into this and executes it:

git diff $(git merge-base master other-branch) other-branch --name-only
  1. What are the actually changes (diff) i made to the branch?
git branch-diff master other-branch

The alias expands this into this and executes it:

git diff $(git merge-base master other-branch) other-branch

Bonus:

# get all file names changed
git branch-diff master other-branch --name-only
# get changes of my_file.cpp
git branch-diff master other-branch -- my_file.cpp
Reasons:
  • Blacklisted phrase (1): stackoverflow
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • User mentioned (1): @jthill's
  • Low reputation (0.5):
Posted by: Brambor