-1

I am trying to find out list of commits between remote repository and local repository across all branches. How do generate this commit list?

I have tried on my local machine running git log command with various options. It does not give me right results.

I expect output of all commits. 4722ec2ac7b8a69ff1ed901a922cf3cd268033f8

1 Answers1

1

Edit:

After fooling in the comments a bit, we arrived at this oneliner:

git branch --format='%(refname:short)' | xargs -I{} git log --pretty=format:"%H" origin/{}...{}

It iterates over your local branch names (assuming there exists a remote version with the same name for each of them) and prints the hashes of the commits that are present in either one of the remote or local branches, but not in both.


Original answer:

First run a git fetch to update your remote tracking branches, then try this:

git log --pretty=format:"%H" --all origin/master...master

This will show what commits are not in origin/master and master at the same time.

That triple-dot syntax is all over git commands (there's also the double-dot one); they're not exactly consistent though and I recommend this answer if you want to dig deeper.

The --all shows the other branches as well.

You can tune it more to your liking by messing around with the dots, order, the --all flag, and even the ^ operator.

Bonus:

You could devise a strategy to still use the iterative solution without a strict one to one mapping of local branches to remote branches with a simple text file and then just cat piping it into xargs.

Nei Neto
  • 438
  • 2
  • 9
  • `--all` is ignored when a commit or range is explicitly given. Also consider a `--pretty=format:"%H"` instead of `--oneline --graph` since OP wanted a simple list of commit hashes. But the problematic point remains the need to run this for each branch with its remote counterpart. – Romain Valeri Jul 24 '19 at 00:21
  • That is not correct. `--all` will actually bring all commits and if they are not in either of the branches listed, they will show up. Your suggested formatting will only make it worse for whoever is reading it. Ultimately, I did say it is not *exactly* what he asked. – Nei Neto Jul 24 '19 at 17:39
  • I don't get your point about hte format I suggested : didn't OP ask for a list of hashes? If the list is to be fed to a script, which is unknown to us at this point, `--oneline --graph` output is useless. My remark tried to stick to OP's question. – Romain Valeri Jul 24 '19 at 17:53
  • You're right. I was answering several questions and got it mixed up. I'll edit my answer. – Nei Neto Jul 24 '19 at 18:05
  • I was thinking: if he just wants a list of hashes of commits regardless of context, we could iterate over all branches and compare `origin/${branch}...${branch}`. Something like `git branch --format='%(refname:short)' | xargs -I{} git log --pretty=format:"%H" origin/{}...{}`. What do you guys think? – Nei Neto Jul 25 '19 at 15:59
  • I was on the same train of thoughts you are. But ironically enough (not that it's rare but...) it seems we two care more than OP after all XD. Upvoted for tenacity! (but editing the answer is better than just commenting, as a sidenote) – Romain Valeri Jul 25 '19 at 16:12