Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pushing an existing Git repository to Github only sends about half the commits?

I have a local Git repository I've been developing under for a few days: it has eighteen commits so far. Tonight, I created a private Github repository I was hoping to push it to; however, when I did so, it only ended up pushing eight of the eighteen commits to Github. I deleted the Github repo and retried, with the same result.

Any thoughts on why this might be happening? I've done this procedure before without a few times successfully, so I'm a bit stumped.

Update: There is, and has always been, only the master branch in this repo. Just to address a few of the posted answers...

like image 733
rpj Avatar asked Oct 26 '08 02:10

rpj


1 Answers

I took a look at the repository in question and here's what was going on:

  • At some point, rpj had performed git checkout [commit id]. This pointed HEAD at a loose commit rather than a recognized branch. I believe this is the "dangling HEAD" problem that CesarB is referring to.
  • Not realizing this problem, he went on making changing and committing them, which bumped HEAD up every time. However, HEAD was just pointing at a dangling chain of commits, not at a recognized branch.
  • When he went to push his changes, git pushed everything up to the top of master, which was only about halfway through the current tree he was on.
  • Confusion ensued

This diagram should make it more clear:

                 -- D -- E -- F
                /             ^
   A -- B -- C -              |
   ^         ^               HEAD
   |         |
 remote    master

When he tried to push his changes, only A through C were pushed and remote moved up to C. He couldn't get commits D through F to push because they aren't referenced by a known branch.

Here's what you see when you're in this state:

$ git branch
* (no branch)
master

The solution is to move master up to F in the dangling chain of commits. Here's how I did it.

  • Create a legitimate branch for the current state:

    git checkout -b tmp

    • The tmp branch is now pointing at commit F in the diagram above
  • Fast-forward master to tmp

    git checkout master

    git merge tmp

    • master is now pointing at commit F.
  • Throw away your temporary branch

    git branch -d tmp

  • You can happily push to the remote repository and it should send all of your changes.

like image 66
Avien Avatar answered Oct 25 '22 04:10

Avien