Accidental commit; how to not push an unpushed commit in Magit Emacs

送分小仙女□ 提交于 2019-12-02 12:48:36

Point at test, press E to start a rebase. M-n two swap commits. C-c C-c to finalize. Resolve merge conflicts if any and done.

This is more a git question than an emacs or magit question really. If I understand you correctly, you want to get rid of older commits. One way to go about this is to re-order your commits and than get rid of the last two commits. The first amounts to picking the right commits during rebase, the latter amounts to using the right incantation of git reset. I would suggest you take a look at this link on reordering commits. In addition, I would urge you to take a (ton of) look(s) at this useful fixup section of the step-by-step adventure through git.

Like @abo-abo said, initiate an interactive rebase by putting point on the first commit you want to remove and then pressing E (on Magit's next version ee.

A new log-like view appears, with every line prefixed with an action, initially pick. Then press n to move to the first commit you want to remove, and k, which will strike out that line meaning to drop that commit. (That's what happens in the ui, when this information is later feed to Git, the line is actually removed). This also moves to the next line, which in this case is the other commit you want to remove. So press k again.

Now that all commits you want to remove are marked as such, press C-c C-c to tell Git to make it happen.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!