Reputation: 1920
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"
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?
Upvotes: 0
Views: 1333
Reputation: 487993
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 master
s 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.
Upvotes: 2
Reputation: 106400
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 can inspect these two commits closer by running git diff <SHA1> <SHA2>
and see if there's anything truly different with them.
Upvotes: 0