1

The following commands reveal what I just did:

Z:\www\gg\web\tests\sample-repo-cloned>git log --all --source --graph
* commit ce7ae79a2b993b780002dbc5eac650fa49427df0       refs/heads/qux
| Author: myname <myemail@gmail.com>
| Date:   Sun Sep 25 00:24:42 2011 +0300
|
|     qux another
|
* commit ef2ea79f40d8e77e47cba31954ef2093c534cc17       refs/heads/qux
| Author: myname <myemail@gmail.com>
| Date:   Sun Sep 25 00:15:56 2011 +0300
|
|     qux
|

Z:\www\gg\web\tests\sample-repo-cloned>git branch
* master
  qux

Z:\www\gg\web\tests\sample-repo-cloned>git checkout qux
Switched to branch 'qux'

Z:\www\gg\web\tests\sample-repo-cloned>notepad2 qux.txt

Z:\www\gg\web\tests\sample-repo-cloned>git add qux.txt

Z:\www\gg\web\tests\sample-repo-cloned>git commit -m "qux more stuff"
[qux 1d18327] qux more
 1 files changed, 2 insertions(+), 1 deletions(-)

Z:\www\gg\web\tests\sample-repo-cloned>git log --all --source --graph
* commit 1d183278e78b8896d882822dacb4aad5bb8cf1bd       refs/heads/qux
| Author: myname <myemail@gmail.com>
| Date:   Sun Sep 25 00:39:06 2011 +0300
|
|     qux more
|
* commit ce7ae79a2b993b780002dbc5eac650fa49427df0       refs/remotes/origin/qux
| Author: myname <myemail@gmail.com>
| Date:   Sun Sep 25 00:24:42 2011 +0300
|
|     qux another
|
* commit ef2ea79f40d8e77e47cba31954ef2093c534cc17       refs/remotes/origin/qux
| Author: myname <myemail@gmail.com>
| Date:   Sun Sep 25 00:15:56 2011 +0300
|
|     qux
|

My question is this: why did the first two commits change their "source" from refs/heads/qux to refs/remotes/origin/qux? They did that after the third commit. I don't understand this. What's the logic behind that "source"? It seems to be changing randomly.

Tower
  • 98,741
  • 129
  • 357
  • 507

1 Answers1

2

The --source parameter to git log is just a bit confusing, I'm afraid. It means that each commit will be shown with the ref by which it was found - it doesn't mean that it will list all refs that contain that commit. In your case, the hypothetical output of a similar option that included all of refs that contain that commit would be:

* commit 1d1832       refs/heads/qux
| Author: myname <myemail@gmail.com>
| Date:   Sun Sep 25 00:39:06 2011 +0300
|
|     qux more
|
* commit ce7ae7       refs/heads/qux refs/remotes/origin/qux
| Author: myname <myemail@gmail.com>
| Date:   Sun Sep 25 00:24:42 2011 +0300
|
|     qux another
|
* commit ef2ea7       refs/heads/qux refs/remotes/origin/qux
| Author: myname <myemail@gmail.com>
| Date:   Sun Sep 25 00:15:56 2011 +0300
|
|     qux

... and you can confirm that by browsing the history with gitk --all, or trying git branch -a --contains ef2ea7, etc.

So, all that's happening is that when you ran the git log the second time was that it checked the origin/qux remote-tracking branch first, and then the qux branch that you're working on. As to why that order should be different between the two invocations, I'm afraid I'm not sure.

The remote-tracking branch is one behind since you haven't updated it via a git push or a git fetch.

Mark Longair
  • 446,582
  • 72
  • 411
  • 327
  • Could this be used as a way to identify whether some commit exists only locally? – Tower Sep 25 '11 at 17:46
  • @rFactor: Absolutely: `git log qux ^origin/qux` (or its [equivalent form](http://stackoverflow.com/questions/5256249/git-diff-doesnt-show-enough/5257065#5257065), `git log origin/qux..qux`) will show you all the commits in `qux` that aren't in `origin/qux`. – Mark Longair Sep 25 '11 at 18:43