I'd like to see which files were touched after having fetched new commits. I want it in the same way that you'd see the files after a merge: list of files, with "x times" + (for lines inserted) and "y times" - (for lines deleted).
I've tried:
git log --pretty=format:'%h %d %s %an %ar' --date=short --stat HEAD..origin
but:
it shows me commits one by one -- while I want to see the whole set of touched files as if there was only one big commit
it does not stop at old commits I already had on my machine.
So, the goal here is really to see at a glance: if I merge all the new commits, which files are changed by the incoming commits?
The correct way to get the type of report you are looking for is to use
git diff
. For example:If your local branches and their upstream counterparts always follow the same pattern (e.g.
foo
andorigin/foo
), then writing a small shell function into an alias should work - something like this in your.gitconfig
:If you have remotes that aren't named
origin
, or if you're not in the habit of using matching branch names, it becomes more complex, and you might need a full-on shell script to take a branch, find it's upstream partner, and then run the appropriategit diff
command.EDIT: to incorporate automatic branch determination:
You ask
If you fetch multiple times without doing a
merge
or arebase
, then diffing frommerge-base
of your branch to your upstream will give you the sum of all of those fetches, and not just the most recent recent fetch. I find it useful to have both - I alias one of them tounmerged
and the other towhatfetched
.Also, git provides builtin functionality to identify your upstream that will work even if the branch you are tracking doesn't have the same name, this is via the special ref
@{u}
.So for what you would want, you would need to check
That will tell you whether or not your branch has an upstream.
To get the name of your upstream you could use
This will print our
origin/$BRANCH
, and will work even if you branch is tracking a branch with a different name. Assign that to $UPSTREAMSo see just the most recent fetch (
whatfetched
), you would use the reflog to show only the changes between where upstream is currently pointing and where it was pointing previously.If you wanted to see what precisely you were looking at here you could use something like
To see the sum of all changes you haven't incorporated (
unmerged
), you would want to diff from themerge-base
of your branch and the upstream to the upstream with