Reputation: 98
Here is my structure of Git repositories (local and remote).
Local
Remote
Below is status of how many commits each branches ahead of relatively.
git rev-list --left-right --count master...origin/master
0 15
git rev-list --left-right --count my-workingcopy...origin/master
40 15
git rev-list --left-right --count my-workingcopy...origin/my-workingcopy
0 0
Now I want to bring those latest changes(15 commits) on the master, in to my-workingcopy. So I do following steps.
git checkout master
git pull origin master
git checkout my-workingcopy
git rebase master
So I end up with following state.
git rev-list --left-right --count master...origin/master
0 0
git rev-list --left-right --count my-workingcopy...origin/master
40 0
git rev-list --left-right --count my-workingcopy...origin/my-workingcopy
15 7
Over here, I am having trouble with the last command where it shows my-workingcopy is behind from origin/my-workingcopy by 7 commits. It is understandable that it is ahead from remote as a result of rebase, but what causes it to get behind from the remote, given that they were in sync before doing the rebase.
Any clarification on this would be helpful.
Upvotes: 2
Views: 112
Reputation: 12205
When doing a rebase, you are rewriting history on your current branch.
You rewind your current branch to a point where it was equal to the other branch (basically putting the commits on the current branch aside), and then apply the commits that are on your current branch, but not on the other branch. With each commit, git might automerge, so it might not be exactly equal to what it was before the rebase (as the starting point is different).
It might be that 7 of your 40 commits needed to be changed, so they are no longer the same as they were when they were last pushed. Shouldn't be cause for worry. But if you get an error when you push, it might be time to stop and rethink things.
Upvotes: 4
Reputation: 30212
The thing is that the revisions have no relation to the original revisions.... to git they are different revisions.... so on the origin branch you have the original 7 revisions.... on your local branch you have other 7 revisions (plus the 8 coming from master, I would assume) different from the 7 on the remote branch.
Upvotes: 0