Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ahead by x commits behind by y commits after rebase in GitHub

I recently merged last y commits into one through the following code

git rebase -i HEAD~y --> Then I squash all the y commits into (by editing the file) -->Then I did a reset to the Head using git reset --soft HEAD~y -->Then I commited everything by using git commit

Now my git hub shows I am ahead by 1 commit and behind by y commits (in github windows).

Now git pull -> gets all the current commits from the master and include this new merged commit once again. Now I am ended up having y+1 commits. Can anyone explain how can I push my recent merged commits.

I am quiet amateur to GitHub. It would be also helpful if anyone can share the basic architecture of GitHub. All I can find is how to create a repository, etc.

Thanks for your time

like image 814
Joe 89 Avatar asked Feb 09 '15 13:02

Joe 89


1 Answers

You rebased your 'y' commits into 1 using the git rebase command. So now you have all these commits created into 1. Then you undo that and the next previous y commits with git reset --soft HEAD~y This step takes your commit and the next y-1 commits and removes them from your local branch's history but leaves the patches. These changes you then commit.

I am assuming that the first y commits that you rebased were not pushed to Github but the second y were. So now when you pull, Git sees that you have created one commit in your local repository (the massive merge ball) and y commits that exist in Github that you don't have because you reset and merged them into one single commit.

After rebasing there is no need to reset your branch, this is what caused your problems. To fix things what you will need to do is:

git reset HEAD^
git stash -u
git pull
git stash pop

What this does is undoes your one commit with the all the massive changes that you have. Sets it aside so that you can bring in the changes that you are missing from Github. Pulls the commits that you are behind from Github and then reapplies that changes that we set aside. I believe that changes that you are repeating will no longer show up in the diff and if you commit the changes now will find that you are only ahead by 1 commit as expected.

like image 128
Schleis Avatar answered Oct 16 '22 10:10

Schleis