git重置 - hard<目标分支>
我有一个主分支 /生产,该分支机构目前处于干净状态,也是一个发展的分支机构,途中的某个地方因许多人在分支上工作并进行更改而出现了问题。我想做的是将开发分支重置为再次与主相等,但不会影响实际的主分支 /生产。因此,从本质上讲,发展仍在发展,但看起来就像大师一样。
这是安全的吗?
GIT结帐开发 git重置 - hard大师
I have a master branch / Production which is in a clean state right now and also a develop branch which somewhere along the way went awry with numerous people working on branches and committing changes. What I want to do is reset the develop branch to be equal with master again but not affect the actual master branch / Production. So essentially develop remains develop but looks just like master.
Is this safe?
git checkout develop
git reset --hard master
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这是安全,一个更好的问题可能是这是个好主意。您遗漏了一个一步,突出了这一点。以下是您可以重置
将
开发为master
的方法:请注意,最后一步是力推动,为重写
开发
在您的远程服务器。它通常皱着眉头来强制推送共享分支,因为这会影响使用该分支的每个人,因为所有正在进行的分支机构都需要使用-
flag来修复它们。此外,在您的情况下,您可能有很多 good 在开发
上您会丢失的工作,所有这些工作都需要重新重新进行,然后再重新 - 合并到新的开发
中。通常,这里更好的方法是隔离问题提交,而只需在
开发
上恢复这些问题(或添加新提交)即可。听起来您尝试了这一点,并准备好扔毛巾并与硬重置一起进行。只要您和您的团队了解这样做的效果,就可以了。Yes, it's safe, however, a better question might be whether or not it's a good idea. There is a step you left out which highlights this point. Here's how you can reset
develop
tomaster
:Note the last step is a force push, which is necessary in order to rewrite the
develop
branch on your remote server. It's generally frowned upon to force push shared branches, because this affects everyone who is using that branch, as all of their in-progress branches will need to be rebased using the--onto
flag to fix them. Furthermore, in your case, you likely have a lot of good work that is ondevelop
that you will lose, and all that work will need to be rebased and then re-merged into the newdevelop
.Typically the better approach here would be to isolate the problem commit(s) and just revert those (or add new commits with the fix) on
develop
. It sounds like you attempted that and are ready to throw in the towel and go with the hard reset. That's OK as long as you and your team understand the effects of doing so.