Is there a way to see what commits have been pulled in from the remote repository after you do a git pull --rebase
?
In other words: git pull
will show a summary of changed files at the end (like git diff --stat
). Git pull --rebase
does not. How can I see this information anyway, if at all possible?
I know this is possible after a normal git pull
or by doing a manual git fetch
first, by comparing local & remote branches using git log master..origin/master --stat
or similar, but this does not work after a git pull --rebase
, unless I'm doing something wrong...
To clarify, my question is 2-part:
1) How to view diffstat (summary of changed files) after a git pull --rebase
, similar to what git pull
shows.
2) How to view log of all new "incoming" commits after a git pull --rebase
.
There is no need to do a git pull after you have rebased your feature branch on top of master . With your current workflow, the reason why git status is telling you this: Your branch and 'origin/feature' have diverged, and have 27 and 2 different commits each, respectively.
This two git commands are not interchangeable. Git pull downloads the newest changes from the remote repository and applies the changes to your local repository. Generally, git pull is git fetch and git merge. Rebasing on the other hand can be a replacement for git merge .
Git pull rebase is a method of combining your local unpublished changes with the latest published changes on your remote. Let's say you have a local copy of your project's main branch with unpublished changes, and that branch is one commit behind the origin/main branch.
If you just want to take a look at it and you're using Bash, you can run: __git_ps1 . It will display something similar to (feature/avarias|MERGING)(base) , but concerning rebase. This string is meant to compose your prompt by assigning it to variable PS1 .
Actually, git rebase
has had this all along (well, since 1.6.something). Remember that git pull
is just git fetch
followed by either git merge
or git rebase
(as directed by various options and settings). That is, git pull
does a pair of underlying git operations.
The reason it does not work after you have finished your git pull
is that git pull
is in fact that pair of operations, and if you just did one pair, there are probably no new changes brought in by your second git fetch
, so there is nothing new to show. If you were to use your reflog history to reset items to the state they were in before the first pair of operations, the second pair of operations would have something to show.
You can (as I see VonC has already noted) get an after-the-fact report on what changed in either the upstream or your local branch using your own reflogs. But presumably you want to see this on the next git pull
even if that does a rebase
, and that's where a sneaky set of git defaults come in.
If you manually add --stat
to your git pull
line, the pull
script passes this option on to either git merge
or git rebase
(whichever one it runs). If you leave this option out, git relies on a default option.
The default --stat
option for git merge
is the setting in your configuration's merge.stat
, which defaults to True. The default --stat
option for git rebase
is the setting in your configuration's rebase.stat
, which defaults to False.
Let me repeat that, because it's just peculiar and non-obvious (I only discovered this because of your question—I generally avoid git pull
myself).
The default --stat
option for merge
is True
but the default --stat
option for rebase
is False
.
If you set the defaults yourself, you can make the stat output show up.
Alternatively, you can pass an explicit --stat
to git pull
.
Note that you can also set pull.rebase
(to either True
, meaning default to rebasing, or preserve
, meaning default to rebase with --preserve
as well), or branch.name.rebase
(to True
or preserve
), to make git pull
use --rebase
. This is independent of whether you supply --stat
as a pull
argument.
Edit: VonC's answer is gone (at least right now) but there are bits of it in various comments. The trick to use after the fact is that when git fetch
updates origin/develop
, your own reflog now contains an origin/develop@{1}
: your own previous value for origin/develop
, before git fetch
updated it. Thus, you can select the revision-set that came in with origin/develop@{1}..origin/develop
. Diffing those two with --stat
will get you the desired output. Note that you may, or may not depending on your particular shell, have to quote the curly braces in the @{1}
part.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With