git重置 - hard<目标分支>

发布于 2025-01-30 02:21:10 字数 184 浏览 4 评论 0原文

我有一个主分支 /生产,该分支机构目前处于干净状态,也是一个发展的分支机构,途中的某个地方因许多人在分支上工作并进行更改而出现了问题。我想做的是将开发分支重置为再次与主相等,但不会影响实际的主分支 /生产。因此,从本质上讲,发展仍在发展,但看起来就像大师一样。

这是安全的吗?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

装纯掩盖桑 2025-02-06 02:21:10

这个安全吗?

是的,这是安全,一个更好的问题可能是这是个好主意。您遗漏了一个一步,突出了这一点。以下是您可以重置开发为master的方法:

git fetch
git switch develop
git reset --hard origin/master
git push --force

请注意,最后一步是力推动,为重写开发在您的远程服务器。它通常皱着眉头来强制推送共享分支,因为这会影响使用该分支的每个人,因为所有正在进行的分支机构都需要使用- flag来修复它们。此外,在您的情况下,您可能有很多 good 开发上您会丢失的工作,所有这些工作都需要重新重新进行,然后再重新 - 合并到新的开发中。

通常,这里更好的方法是隔离问题提交,而只需在开发上恢复这些问题(或添加新提交)即可。听起来您尝试了这一点,并准备好扔毛巾并与硬重置一起进行。只要您和您的团队了解这样做的效果,就可以了。

Is this safe?

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 to master:

git fetch
git switch develop
git reset --hard origin/master
git push --force

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 on develop that you will lose, and all that work will need to be rebased and then re-merged into the new develop.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文