In Git, I understand that a branch is a pointer to a commit.
How do I make a specific branch point to a specific commit? Say I want to make master
point at 1258f0d0aae...
, how do I do that?
You can make master
point at 1258f0d0aae
this way:
git checkout master
git reset --hard 1258f0d0aae
But you have to be careful about doing this. It may well rewrite the history of that branch. That would create problems if you have published it and other people are working on the branch.
Also, the git reset --hard
command will throw away any uncommitted changes (i.e. those just in your working tree or the index).
You can also force an update to a branch with:
git branch -f master 1258f0d0aae
... but git won't let you do that if you're on master
at the time.