Reputation: 448
Upon coding, I realized I had made a mistake. I used
git checkout 7e57dbf5a7245...
to revert to an older commit. Now when I commit using
git commit -a
it says I am committing to a [detached HEAD f69ae14]. When I use
git push origin master
it says Everything's up to date... What do I type to push this [detached head] commit back to the master?
Upvotes: 0
Views: 158
Reputation: 1922
Going off of what max said, your log initially looks like:
*-*[7e57db]-*-*<master>
You checkout 7e57db, and git commit
, and you end up with:
*-*[7e57db]-*-*<master>
\
*<HEAD>
What you'd really like to do is take the commit at HEAD, and replay the changes it introduced on 7e57db onto master. The command you use for this is git rebase
. Specifically, once you had made the commit, you would run:
git rebase master
At this point your history would be:
*-*[7e57db]-*-*<old-master>-*<master>
Then you could git push origin master
to update the remote ref.
Upvotes: 1
Reputation: 34407
You current log must be something like this
*-*-*-*[7e57db]-*-*-*<master>
\
*-*-*-*<HEAD>
Now you should reset master
to current HEAD
position, make master
current branch and push it to origin
:
git branch -f master HEAD
git checkout master
git push origin master
Note that you will lose all commits between 7e57db
and current master
.
Upvotes: 1
Reputation: 1764
you can reset the head to the detached head by using
git reset --hard 7e57dbf5a7245...
# and then
git push origin master --force
by doing this, you will lose your changes between old and new head.
If you want to keep these changes, you could create a new branch from your detached head and merge it into your head, and then commit your changes and push the new branch.
Upvotes: 0