1

I wanted to go to a previous version, then I did

git checkout 577ba726a9e21a62d33f2f1837ccb0a47ee434b4

git commit -m "revert"

Then I realise that it does not work as what I expected: the code in the github webpage is not what was in 577ba726a9e21a62d33f2f1837ccb0a47ee434b4. So I manually modified the whole code as what was in 577ba726a9e21a62d33f2f1837ccb0a47ee434b4. Then I did

git add .
git commit -m "m"
git push -u origin master
git pull origin master

But it gives me

HEAD detached from 577ba72
nothing to commit, working tree clean
Branch master set up to track remote branch master from origin.
Everything up-to-date
From https://github.com/chengtie/funfun
 * branch            master     -> FETCH_HEAD
Already up-to-date.

And the code in my local disk is NOT the code in the github page.

How could I align these two places? I am totally lost...

SoftTimur
  • 5,630
  • 38
  • 140
  • 292
  • I'm not going to close this right away as a duplicate (since it's not clear to me what you are concerned about *right now*), but see https://stackoverflow.com/q/4114095/1256452 for the answer to the original problem you were describing. – torek May 25 '17 at 16:08

1 Answers1

0

You are in a "detached HEAD" state because you do not have a local branch which points to 577ba726a9e21a62d33f2f1837ccb0a47ee434b4. You could create one however with:

git checkout -b saveSpot

This will take you out of the detached state.

--

If you want your master branch to point to a particular commit you can use the reset command like this:

git checkout master
git reset --hard 577ba726a9e21a62d33f2f1837ccb0a47ee434b4
git push -f origin master

But a warning: This will overwrite your master branch, hence the -f which is to "force" a push. So make sure your teammates are aware of what's going on before you push.

Jonathan.Brink
  • 23,757
  • 20
  • 73
  • 115
  • Now I just want my local code to override what is in github, and get the control of `master` back... What should I do? – SoftTimur May 25 '17 at 16:07
  • If you want your local code to override what is in GitHub then following the push command I have above should accomplish that. – Jonathan.Brink May 25 '17 at 16:08