Here are two different questions but I think they are related.
When using Git, how do I find which changes I have committed locally, but haven\'t yet pushed
Incoming commits across all branches can be shown with the following approach.
The command git fetch-diff
becomes available by adding an executable called git-fetch-diff
to your PATH, containing:
#!/bin/bash
set -e
# get hashes before fetch
old_hashes=$(git log --all --no-color --pretty=format:"%H")
# perform the fetch
git fetch
# get hashes after fetch
new_hashes=$(git log --all --no-color --pretty=format:"%H")
# get the difference
added_hashes=$(comm -1 -3 <(echo "$old_hashes") <(echo "$new_hashes"))
# print added hashes
[ ! -z "$added_hashes" ] && echo "$added_hashes" | git log --stdin --no-walk --oneline
Commit hashes are compared before and after the fetch. The difference is piped back to git log
for pretty printing. The appearance of the printed log can be further tuned to your liking with arguments such as --pretty=<format>
and --graph
.
Note: You might want to cap how far git log
will go back in time depending on how much a bash variable can hold on your system, or for performance reasons. This can be done by adding the argument --max-count=<count>
.
git-out is a script that emulates hg outgoing
quite accurately. It parses on "push -n" output, so it produces accurate output if you need to specify additional arguments to push.
Use "git log origin..HEAD"
Use "git fetch" followed by "git log HEAD..origin". You can cherry-pick individual commits using the listed commit ids.
The above assumes, of course, that "origin" is the name of your remote tracking branch (which it is if you've used clone with default options).
When you do git fetch, all the contents including branches,tags ( refs) are stored temporarily in .git/FETCH_HEAD whose content can be viewed with command: git log FETCH_HEAD If you don't use suffix -a with git fetch then by default, FETCH_HEAD's content's will be overwritten by new contents. From these contents, you can view and decide to which branch you want to merge them if you do or you can simple cherry-pick if you want only a few commits from what has been brought by fetch.
Git can't send that kind of information over the network, like Hg can. But you can run git fetch
(which is more like hg pull
than hg fetch
) to fetch new commits from your remote servers.
So, if you have a branch called master
and a remote called origin
, after running git fetch
, you should also have a branch called origin/master
. You can then get the git log
of all commits that master
needs to be a superset of origin/master
by doing git log master..origin/master
. Invert those two to get the opposite.
A friend of mine, David Dollar, has created a couple of git shell scripts to simulate hg incoming/outgoing
. You can find them at http://github.com/ddollar/git-utils.
$ git fetch && git log ..origin/master --stat
OR
$ git fetch && git log ..origin/master --patch
$ git fetch && git log origin/master.. --stat
OR
$ git fetch && git log origin/master.. --patch