ardakshalkar
ardakshalkar

Reputation: 625

How to push after I checkout to previous commit, then I made some commits, and now when I push, changes are not sent

I made checkout to the previous commit Then I made changes to code and committed, what should I do now, to push and pull from the outer repository.

How can I return HEAD to the current (which was checkout and edited) version of my code, and integrate it with code on outer repository

Upvotes: 0

Views: 182

Answers (1)

ElpieKay
ElpieKay

Reputation: 30858

It seems you were led to a detached HEAD, which can be seen as a nameless branch. The solution is to find out the commits you made and apply them to the named branch.

From your description, I can't tell what status you are now in. So first, use git reflog to find out the commits. git reflog prints a list of commits that HEAD once have pointed at. From top to bottom, find out the FIRST commit which you are familiar with and you are sure is the one or one of the commits you have made on the nameless branch. If you made only one commit, the one is what we are seeking for. If you made more than one, use git log <commit> to find all of them. If the situation is more complicated, which I hope not, use git reflog and then git log multiple times against the possible commits to find out all the commits which seem lost.

Second, apply these commits onto the named branch. Suppose you want them to be on master.

# switch to master
git checkout master

# apply the commits from the oldest to the youngest
git cherry-pick A B C

Finally, update and push master.

git pull origin -r master
git push origin master

Upvotes: 1

Related Questions