Is there a way to see what files have changed in a branch?
问题:
回答1:
An alternative to the answer by @Marco Ponti, and avoiding the checkout:
git diff --name-only <notMainDev> $(git merge-base <notMainDev> <mainDev>)
If your particular shell doesn't understand the $() construct, use back-ticks instead.
回答2:
All you have to do is the following:
git checkout <notMainDev>
git diff --name-only <mainDev>
This will show you only the filenames that are different between the two branches.
回答3:
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
回答4:
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.
回答5:
I really liked @twalberg's answer but I didn't want to have to type the current branch name all the time. So I'm using this:
git diff --name-only $(git merge-base master HEAD)
回答6:
git whatchanged
seems to be a good alternative.
回答7:
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.
回答8:
git show --stat origin/branch_name
This will give you a list of the files that have been added or modified under this branch.
回答9:
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>)
回答10:
Expanding off of what @twalberg and @iconoclast had, if you're using cmd for whatever reason, you can use:
FOR /F "usebackq" %x IN (`"git branch | grep '*' | cut -f2 -d' '"`) DO FOR /F "usebackq" %y IN (`"git merge-base %x master"`) DO git diff --name-only %x %y
回答11:
The following batch file is based on twalberg's answer but will work in Windows:
@ECHO OFF
C: :: <== OR USE A DIFFERENT DRIVE
CD \path\to\where\git\files\are :: <== CHANGE TO THE ACTUAL PATH
SET /p b="Enter full path of an ALREADY MERGED branch to compare with origin/master: "
bash --login -i -c "git diff --name-only %b% $(git merge-base %b1% origin/drop2/master)"
PAUSE
The above assumes that the main branch is origin/master and that git bash was included when Git was installed (and its location is in the path environment). I actually needed to show the actual differences using a configured diff tool (kdiff3) so substituted the following bash command above:
bash --login -i -c "git difftool --dir-diff %b% $(git merge-base %b1% origin/drop2/master)"
回答12:
I use grep so I only get the lines with diff --git which are the files path:
git diff branchA branchB | grep 'diff --git'
// OUTPUTS ALL FILES WITH CHANGES, SIMPLE HA :)
diff --git a/package-lock.json b/package-lock.json
回答13:
git diff --name-only master...branch-name
to which we want to compare.