0

So, I am a little confused on how git log --graph works.

Here is my repository on GitHub: https://github.com/Snedden/capstone

I haven't created any branches apart from the master branch.

But when I run the command git log --graph (on my local repository) it appears I had a branch around the commit "standardised urls for better portability"

git log output

So my question is, if that's not a separate branch then why does it appear to be like a separate branch in the git log output?

NOTE: Some info, when I tried pushing on c228400 git said I had to pull first as it thought my remote is ahead of my local, I am not sure how this is possible as I always did linear pushed some the same account.

Community
  • 1
  • 1
Snedden27
  • 1,870
  • 7
  • 32
  • 60
  • You have worked the 3 commits in the testBranch. Then you merged it on master. That is the log says. =0) – Eddy Hernandez Sep 29 '16 at 14:05
  • Possible duplicate of [Git pull results in extraneous "Merge branch" messages in commit log](http://stackoverflow.com/questions/8509396/git-pull-results-in-extraneous-merge-branch-messages-in-commit-log) – Scott Weldon Sep 29 '16 at 15:43
  • @scott thanks for pointing ou,reading through the answer begs another question when I did a pull request how did my remote assume that its out of sync to my local since all I did was linear commits and pushes – Snedden27 Sep 29 '16 at 16:23
  • I'm not sure what you mean. The remote doesn't "assume" anything; it looks like you pushed commits from two different computers. If you haven't already, read [the second answer to that question](//stackoverflow.com/a/8523117/2747593), it explains things nicely. – Scott Weldon Sep 29 '16 at 16:34

2 Answers2

2

The answer is in your graph (which is an image, so I've transcribed it here, more or less):

*  44ccab (HEAD -> testBranch, origin/master, origin/HEAD, master)
|    Merge branch 'master' of https://github.com/Snedden/capstone
|\
| * c228400 standardised urls for better portability
* | 90bbf9e added stage axis and d3 library
* | 2d0ce65 standardised urls for better portability
|/
* 4c?02a4 datasets implemented

You did, in fact, merge two branches.

The two branches you merged were master and master.

One of these two masters is your master. The other is 'master' of <another repository>.

This is the kind of merge that git pull makes. Remember, git pull means "Run git fetch, then run git merge unless I tell you in advance to run git rebase instead of merging."

The message that git pull sets for the merge is Merge branch 'name' of URL. The name part comes from the branch you tell your Git to use. The contents of that branch are whatever your Git retrieves from the given URL after those contents are brought into your repository (under some other name, since obviously master is already in use!).

That is, you merged in someone else's master. Now, that "someone else" is probably you, but Git doesn't know or care, it just knows the URL.

If you run git fetch instead of git pull, you can choose whether to run git merge or git rebase after you've done the fetch, instead of deciding before, sight-unseen. Moreover, if you then choose to merge, you'll merge by the name you are using in your repository, i.e., origin/master, rather than by the weird name master :-) that some other guy is using in that other repository over there on github.com. This may make more sense to you later (or maybe not).

Given that the commit messages of 2d0ce65 and c228400 are the same, I suspect you rebased or amended a commit after pushing c228400. This made a copy of the commit (an imperfect copy, on purpose, with something changed). You then added the "stage axis and d3 library" commit, and then when you ran git pull, your Git dutifully merged your two commits, 2d0ce65 plus 90bbf9e, with the other guy's one commit, c228400, found on github.

Those were your two branches: your branch master, and that other you's master over on GitHub.

torek
  • 448,244
  • 59
  • 642
  • 775
  • "Given that the commit messages of 2d0ce65 and c228400 are the same, I suspect you rebased or amended a commit after pushing c228400" your inference was spot on,I did amend an commit, that's what made git to ask me to pull first, – Snedden27 Sep 29 '16 at 19:44
0

You have from what I can see two branches: testBranch and master, so the fact that this can occur seems correct to me.

To explain this image, we have to remind ourselves that Git is a DAG - directed acyclic graph - in that it always draws nodes in a specific order. In this context, the order that your commits were pulled in are based on ancestry; testBranch likely branched off of master to do some extra work.

I believe that the two commits - 2d0ce65 and 90bbf9e - are work that was commited to master. The third commit - d228400 - was work done on testBranch. The two branches have a common ancestor in 4c002a4, but diverged afterwards, which is why there are two different paths.

Now, as to why the commit messages appear the same, this could mean any one of these things:

  • You rebased your work against master
  • You cherry-picked that commit into master or from master into testBranch
  • You simply copied the same description over and the commits are completely different

You can inspect these two commits closer by running git diff <SHA1> <SHA2> and see if there's anything truly different with them.

Makoto
  • 104,088
  • 27
  • 192
  • 230
  • thanks for your answer, but the test branch is created after the commit 44cca4b, it didn't exist before that and it doesn't exist on my git hib remote yet It seems to me when I tried to push at c228400 git decided my remote is ahead of my local repository(I don't know how this is possible) and made to pull first causing the merge – Snedden27 Sep 29 '16 at 16:30
  • @Snedden27: You don't have a remote testBranch; that's a local one. You'd see it show up if it were remote as origin/testBranch. – Makoto Sep 29 '16 at 16:32
  • yes it is the test branch is something I just created,its not relevant to the question . I just wanted people not to get confused with it – Snedden27 Sep 29 '16 at 16:34