1

In my git repo, There are two branches except master. nyteam and cfteam.

Switch to nyteam branch

Commit some changes and pushed to origin/nyteam (so far only one commit is pushed)

Switch to cfteam

git status
Your branch is up-to-date with 'origin/cfteam'

git pull origin nyteam
git status

Your branch is ahead of 'origin/cfteam' by 5 commits.

Now the question is, where does the other four commits come in place which is actually not done by me.

Can anyone explain this situation ?

Thanga
  • 7,811
  • 3
  • 19
  • 38

2 Answers2

2

Now the question is, where does the other four commits come in place which is actually not done by me.

in order to view the history do this:

git log --oneline --decorate --graph

It will show you the commits in which the branches are pointing to.


where does the other four commits come from?

When you executed:

git pull origin nyteam

nyteam added 4 commits into your current branch which is cfteam so now you have new commits which came from the merged branch.


Here is a sample of something similar:

enter image description here

git log after the merge (pull = fetch + merge)

enter image description here

Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • Thanks for answer. the `git log --oneline --decorate --graph` gives the below response `a249689 (HEAD -> cfteam, origin/nyteam, nyteam)` – Thanga Feb 11 '16 at 12:34
  • This means that the 3 branches pointing to the same commit. all of them. checkout the origin/cfteam branch (you will be in detached head) and see to which commit its pointing to. `git checkout origin/cfteam` – CodeWizard Feb 11 '16 at 12:36
  • I am in origin/cfteam, I dont see the five commits. Does that mean origin/cfteam is not having these commits but cfteam does ? – Thanga Feb 11 '16 at 12:44
  • Exactly. Since you have it locally but you didn't pushed it yet – CodeWizard Feb 11 '16 at 12:49
  • Do you have better understanding now? – CodeWizard Feb 11 '16 at 12:50
  • Yes. Now it is clear.. Thanks for your time. Accepting it – Thanga Feb 11 '16 at 12:51
  • Feel free to ask more if nedded. Glad to help – CodeWizard Feb 11 '16 at 12:58
  • Read this out to understand it better. (feel free to vote if you like it). http://stackoverflow.com/questions/34519665/how-to-move-head-checkout-revert-reflog-reset/34519716#34519716 – CodeWizard Feb 11 '16 at 13:26
  • Upvoted that also.. You are so good at Git especially in explaining – Thanga Feb 11 '16 at 13:32
1

The two branches diverged at a point in the past. The changes to nyteam are represented by four commits. When you do a pull from cfteam into nyteam it has merged the new changed onto the state arrived at by the previous four commits. So the fifth node is a merge, the four before that are the changes in that branch. You are "ahead" because you have cfteam as the origin that nyteam is tracking against.

Andrew
  • 2,943
  • 18
  • 23
  • Thanks for answer. But when i create this new branch `nyteam`, i was in cfteam. So i guess the `nyteam` should be similar to the cfteam at the beginning. then i did a commit. What is the possibility of the other four commits in this ? – Thanga Feb 11 '16 at 12:31