Q:

Get number of changed files in Git between two branches from bash

I'd like to know how can I get a number of changed files between two branches in a bash script i.e.
git diff v1.1.123..master --stat

and this gives a list of files and detailed changed/added/deletion, but I'd need the number of changed files in a bash variable.
OR, anyway to find out if there has been any change between the branches in a bash variable, so that I can do some operations if there's any change or not.

A:

(Answer copied and expanded from comment, though this is now largely a duplicate of several "name or name-status only" questions as well.)
You are already most of the way there. Simply replace --stat with --name-status and then write code to count based on the statuses. (Note also that git diff X..Y means precisely the same thing as git diff X Y: the usual special meaning of .., two dots, goes away in git diff.) 
--name-only would work as well if you don't care to aggregate stats for Add, Delete, Modify, and potentially Copy, Rename, Type-change (e.g., from regular file to symlink), etc.  Whether your diff will detect renames depends on (a) file similarity and (b) options and/or your setting for diff.renameLimit.  Copy detection is similarly under the control of options.  Note that you can also use --diff-filter to select for (or, since git 1.8.5, exclude1) particular changes.
To just count files, piping the diff output through wc -l will suffice (though note that its output has leading white space).

1For instance, git diff A B --name-status --diff-filter=AD will produce just a list of files Added or Deleted.  To exclude Type-change items, git diff A B --name-status --diff-filter=t does the trick in git 1.8.5 or newer; with older versions, you would have to list everything but T, e.g., --diff-filter=ABCDMRUX, depending on whether you asked for pairing breaks.  I'll also note that Unmerged and X(unknown) should never occur here; U status should only occur when invoking a diff against the index.

