Is there a way to see what files have changed in a branch?
git whatchanged
seems to be a good alternative.
I can't believe there are so many ways to do this. I use whatchanged as someone posted before, just with the following arguments:
git whatchanged --name-only --pretty="" origin..HEAD
This just lists the filenames, and only the ones that changed on the current branch.
amazed this has not been said so far!
git diff master...branch
So see the changes only on branch
To check the current branch use
git diff master...
Thanks to jqr
This is short hand for
git diff $(git merge-base master branch) branch
so the merge base (the most recent common commit between the branches) and the branch tip
Also using origin/master instead of just master will help in case your local master is dated
What if it could be as easy as this?
git changed
If you're willing to assume that the main branch is called "master", and that you create your other branches from master, then you can add this alias to your ~/.gitconfig
file to make it that easy:
cbranch = !"git branch | grep '*' | cut -f2 -d' '"
changed = !"git diff --name-only $(git cbranch) $(git merge-base $(git cbranch) master)"
Those assumptions will work for most people in most situations, but you must be aware that you're making them.
Also, you must use a shell that supports $()
. It's very likely that your shell supports this.
The accepted answer - git diff --name-only <notMainDev> $(git merge-base <notMainDev> <mainDev>)
- is very close, but I noticed that it got the status wrong for deletions. I added a file in a branch, and yet this command (using --name-status
) gave the file I deleted "A" status and the file I added "D" status.
I had to use this command instead:
git diff --name-only $(git merge-base <notMainDev> <mainDev>)
For some reason no one mentioned git-tree
. See https://stackoverflow.com/a/424142/1657819
git-tree
is preferred because it's a plumbing command; meant to be programmatic (and, presumably, faster)
(assuming base branch is master
)
git diff-tree --no-commit-id --name-only -r master..branch-name
However this will show you all files which were affected in the branch, if you want to see explicitly modified files only, you can use --diff-filter
:
git diff-tree --no-commit-id --name-only -r master..branch-name --diff-filter=M
Also one can use --name-status
instead of --name-only
to see the status of the files (A
/M
/D
and so on)