我想将我的 master 分支恢复到 8 次提交前的状态
我刚刚意识到我在最近 8 次提交中的某个地方引入了内存泄漏。 最简单的解决方案是恢复到 8 次提交之前,然后仔细添加更改 回来。最简单的方法是什么?
谢谢!
I just realized I introduced a memory leak somewhere in the last 8 commits.
Easiest solution is to revert to 8 commits ago, then carefully add the changes
back in. What is the easiest way of doing this?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看一下
git bisect
。听起来正是您正在寻找的东西。基本上,您告诉它历史记录中已知的好点和已知的坏点,然后它会帮助您执行二分搜索,直到找到有问题的提交。
这是有关其使用的教程: http://www.kernel .org/pub/software/scm/git/docs/user-manual.html#using-bisect
但是,如果您不想这样做,请在您现在所在的位置创建一个临时分支,然后要么执行一堆 git reset HEAD^ 一次提交一个提交,要么执行 git reset HEAD~8 ,然后执行 gitcherry-pick
sha1>
用于您和临时提交之间的每个后续提交。Take a look at
git bisect
. It sounds like exactly what you are looking for.Basically, you tell it a known good point and a known bad point in your history, and then it helps you perform a binary search until you find the offending commit.
Here's a tutorial on its use: http://www.kernel.org/pub/software/scm/git/docs/user-manual.html#using-bisect
But, if you don't want to do it that way, create a temporary branch where you are right now and either do a bunch of
git reset HEAD^
to go up one commit at a time, or dogit reset HEAD~8
and thengit cherry-pick <sha1>
for each subsequent commit between you and your temporary commit.将您的 master 克隆到另一个分支,然后在 master 上 git reset --hard 到有问题的提交。然后使用 gitcherry pick 将每个恢复的提交从 backups 分支引入到 master 分支并进行检查。如果一切正常,则继续下一次提交,依此类推。
如果您不熟悉这些命令,请先阅读我所说的命令,然后再继续操作。 :-)
Clone your master to another branch, then on master
git reset --hard
to the commit in question. Then usegit cherry pick
to introduce each reverted commit from the backups branch to the master branch and inspect. If all ok then proceed to next commit and so on.Please read up on the commands i stated, before actually proceeding if you're not familiar with them. :-)