Git - how to rollback

匿名 (未验证) 提交于 2019-12-03 10:09:14

问题:

I know this question has been asked before but although the given answer git reset --hard HEAD~1 works, I cannot push it to the server since the server is ahead. Pulling obviously puts me right back where I was.

How do I reset the server?

回答1:

you want to force a push, only use this if you are certain of the change.

git push origin --force 


回答2:

Force pushing is an option, if your colleagues accepts to reset their own local branch to the new origin/master (assuming we are talking about that 'master' branch).

git fetch git reset origin/master 

(not a reset --hard, because that would wipe out work in progress and private file)
(note that it will unstage whatever was already added to the index)


The other option, "to undo your cock ups" (if you have already pushed the wrong commit), it to revert it, creating a new one which cancel the previous one.
See git revert.

You can then push (regular push) that revert commit.



回答3:

It all depends on the project's conventions. The safe bet is to use git revert because you can always drop the commit later if that's the policy. If you want to revert a merge, you need to specify which parent you want to revert to ("mainline") with git revert --mainline <parent-number>.

You should ask the project's maintainer to explain what to do in your specific case.


In our team, we use the following set of rules:

  • Only pull using rebase (branch.autosetuprebase=always)
  • master is the only "public" branch
  • Development branches remain "private" even when pushed to our shared server

This means everybody is free to do whatever they wish with their private branches, you can rebase or drop commits as you feel fit. On the other hand, our shared server is configured to refuse forced pushes to master.

That is not to say we never reset master, sometimes (maybe once a year) someone might accidentally push a merge where we think that it would terribly screw up our history. In these exceptional cases one of our git-gurus will write an email to the whole team, explaining what is about to happen and what steps to take to update local clones.



文章来源: Git - how to rollback
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!