1

Short version: the commit made in master by a coworker appears as if it had been done in a branch I just pushed. The scenario is very simple but I don't understand what happened.

I only did two things.

First, I created a branch from master (locally, in a freshly clone repository) and switched to it.

(master) $ git checkout -b my-branch
Switched to a new branch 'my-branch'

I made no other change and about ½ hour later, I pushed the branch (I would have done it immediately but got interrupted).

/c/myrepo (my-branch)$ git push -u origin my-branch
Counting objects: 7117, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4111/4111), done.
Writing objects: 100% (7117/7117), 30.37 MiB | 2.35 MiB/s, done.
Total 7117 (delta 2773), reused 7117 (delta 2773)
To https://stash/myproject.git
* [new branch]      my-branch -> my-branch
Branch my-branch set up to track remote branch my-branch from origin.

Then I went to Stash to check the branch shows up. To my surprise, it looked like below. My coworker, John Doe, had committed a change in master. However, in reality he did so in his master which tracks origin/master (he was not aware of my branch nor interested in it, he was developing as usual). For some reason, Stash shows that changed as if committed in my-branch.

I don't understand this. It's as if git push also got the latest from origin/master and pushed those changes as part of my-branch. But this was a new branch that no one knew about.

I still have that local repo and can run any debugging commands, if needed. Thanks.

Stash history problem

Here's what I see locally.

C:\myproject>git remote show origin
* remote origin
  Fetch URL: https://stash/myproject.git
  Push  URL: https://stash/myproject.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branches configured for 'git pull':
    master merges with remote master
    my-branch merges with remote my-branch
  Local refs configured for 'git push':
    master pushes to master (up to date)
    my-branch pushes to my-branch (up to date)

We are all using Git 2.10.0 and Atlassian Stash v3.11.1.

wishihadabettername
  • 14,231
  • 21
  • 68
  • 85
  • 1
    Execute `git reflog -a` and if applicable tell us what is the top 20-30 `logs`. Please do some cleanup before you paste anything here :) – Samundra Oct 04 '16 at 14:25
  • 1
    If John had pushed his commit to `master` before your clone, his commit is expected to be in the history of `my-branch`. – ElpieKay Oct 04 '16 at 15:44
  • @ElpieKay, can you please clarify why his commit would appear in the history of my-branch and not in the history of master? He did commit in master, after all. Thanks. – wishihadabettername Oct 05 '16 at 13:35
  • 1
    John's commit had been in `master` before you created `my-branch` from `master`. The commit is part of the history of `my-branch` too, as `my-branch` was just a copy of `master` at that time. In the future, `master` and `my-branch` can go into different directions, or we can say `diverged`, but that commit is a common commit of these two branches. As to the details, I recommand you read the chapter *Git Internals* of *Pro Git*. You will find it out how commits and branches work in git, which might be quite different from what you are thinking. – ElpieKay Oct 06 '16 at 11:40

0 Answers0