暂时从 git master 分支中删除代码
我在 git 中跟踪了一个项目,它有一个主分支,该分支成为我的代码的发布版本。我在该分支中有一些代码导致了问题,因为它依赖的外部库当前已损坏。然而,我预计外部库将在未来的某个时候(几周,所以隐藏并不是我真正想要的)被“修复”,并且我希望恢复有问题的代码。
那么问题来了:
如何保存分支中的代码以供将来使用?如果我只是创建一个名为 saveme 的分支,在 master 分支上进行更改,然后尝试将 saveme 合并回 master 以获取“已保存”的代码,这似乎会导致“已经是最新的”。
I have a project tracked in git that has a master branch that becomes the release for my code. I have some code in that branch that is causing problems because an external library that it relies on is currently broken. However, I expect that the external library will be "fixed" at some point in the future (weeks, so stash is not really what I want here) and that I will want to resurrect the problematic code.
So, the question:
How can I save code from a branch for future use? If I simply create a branch called saveme, make changes on the master branch, and then try to merge saveme back into master to get back the "saved" code, this seems to result in "already up-to-date".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您创建
saveme
分支时,您的历史记录如下所示:.... 然后,当您在
master
上进行更多工作时,为了应对损坏的库,您的历史记录如下这样:因此,如果您尝试将
saveme
合并到master
中,它会显示“已经是最新的”,因为saveme
的完整历史记录已包含在master
中。听起来好像您想要的是创建一个与 saveme 完全相同的树的提交,但只是在 master 之上的另一个提交。您可以通过使用git revert
提交E
然后使用D
来完成此操作,但如果您想一次性完成,您可以这样做以下:(这是我在 这个答案。)然后你的历史记录将看起来像:
...但是提交
F
的树将与提交C
的树相同。When you create the
saveme
branch, your history looks like this:.... then when you work more on
master
, to cope with the broken library, your history looks like this:So if you try to then merge
saveme
intomaster
, it says "Already up-to-date" because the complete history ofsaveme
is already contained inmaster
. It sounds as if what you want is to then create a commit which has exactly the same tree assaveme
, but is just another commit on top ofmaster
. You could do this by usinggit revert
for commitE
and thenD
, but if you want to do it in one go, you can do the following:(This is a trivial variation of the recipe I suggested in this answer.) Then your history will look like:
... but the tree of commit
F
will be the same as that of commitC
.