修复“完整”使用 git commit 和 revert 编写代码(我的愚蠢方式)?
我正在分支 A
工作,突然一切崩溃并停止工作。我认为我可能会破坏代码中的某些内容,因此我提交
我的更改并从分支 A
创建了新的分支 B
以将其保留为备份。然后我恢复
分支A
到最后一个工作提交,并开始尝试修复任何可能的错误。后来我意识到服务器有问题而不是我的代码。所以我删除了分支 A 并继续在分支 B 中工作。 我这样做是因为我不是 git 专家,所以我用我的一点知识来解决问题。我相信应该有比我“非常愚蠢”的方式更容易、更聪明、更合适的方法来解决这样的问题:) 有什么建议吗?
I was working on branch A
when suddenly everything crashed and stopped working. I thought I might broken something in my code so I committed
my changes and created new branche B
from branch A
to keep it as a backup. then I revert
branch A
to the last working commit, and start trying to fix any possible bugs. I realised later that the server had a problem not my code. So I deleted branch A
and contenue working in branch B
.
I did this because I'm no git expert so I sorted things out with my little knowledge. I believe there should be much easer, cleverer and more appropriate ways to solve such a problem than my "very stupid" way :)
Any suggestion?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以再次将 A 分支重置为最后一个工作提交,
将 B 中的“未损坏”代码合并回 A 分支,
然后删除 B 分支并继续使用 A 分支。
You could have reset A branch to the last working commit again,
merged the "unbroken" code from B back to A branch,
then delete B branch and continue working with A branch.
你的工作方式没有任何问题。在 Git 中,分支实际上只是指向提交的指针,当您创建更多提交时,指针会随着您向前移动到最后一次提交。鉴于此,除了名称之外,原始分支 A 和当前分支 B 之间没有任何区别。
现在您已经删除了分支 A,如果您愿意,可以将分支 B 重命名为分支 A:
There's nothing wrong with the way you're working. In Git, a branch is really just a pointer to a commit, and as you create more commits, the pointer moves forward with you to the last commit. Given that, there's no difference between your original branch A and your current branch B except the name.
Now that you've deleted branch A, you can rename branch B to branch A if you like: