简体   繁体   English

如何将本地主机还原/重置为HEAD?

[英]How to revert/reset local master to HEAD?

I'm trying to push a older commit to heroku/master, but if I'm not mistaken git push pushes the local master to the remote repo. 我正在尝试将较早的提交推送到heroku / master,但是如果我没有记错的话, git push会将本地主机推送到远程仓库。 So I'm trying to get my local master to match my HEAD. 所以我试图让我的当地主人匹配我的头。

I'm trying to do it without losing the commits I made so I maybe could go back to them whenever I need. 我正在努力做到这一点而又不丢失我所做的提交,因此我可能会在需要时重新找他们。 在此处输入图片说明

Things I've tried: 我尝试过的事情:

# this only set my HEAD on the wanted commit.
$ git reset --hard HEAD
$ git reset --hard 055c700

# this made a new branch called HEAD instead of my actual HEAD, which was a pain to delete afterwards 
$ git checkout -B "HEAD" "master"

The easiest way to do this is: 最简单的方法是:

  1. Point your HEAD to your master first $ git checkout master 将您的HEAD指向您的master第一个$ git checkout master
  2. Make a copy of the branch $ git checkout -b new_master 复制分支$ git checkout -b new_master
  3. Checkout the master branch $ git checkout master 结帐master分支$ git checkout master
  4. Reset to the commit you want your master to be pointed to $ git reset --hard <commit-number> in your case $ git reset --hard 055c700 重置为您希望主服务器指向的提交$ git reset --hard <commit-number>在您的情况下$ git reset --hard 055c700
  5. Force push master to heroku $ git push -f heroku master 强制将master推送到heroku $ git push -f heroku master
  6. Delete the branch new_master 删除分支new_master

You seem to be confusing the term HEAD to mean an actual branch. 您似乎对术语HEAD表示实际分支感到困惑。 HEAD is just a pointer to the last commit of the current branch you are on. HEAD只是指向您当前所在分支的最后提交的指针。 So creating a branch called HEAD would have no effect. 因此,创建名为HEAD的分支将无效。 If you are on the branch HEAD, the pointer HEAD would be at the last commit. 如果您在分支HEAD上,则指针HEAD将位于最后一次提交。 If you are on master it will point to the last commit in master 如果您在master上,它将指向master中的最后一次提交

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM