问题
I did an accidental commit which really makes no sense to have anywhere in history. How can I remove this commit from existence (especially I don't want it appear remotely).
In the magit-status, it shows:
Unpushed commits:
fe73b07 updated gitignore
974e70d test
ab333e6 trying to go with a flat structure
What can I do?
Bonus: actually, I just want to keep the "updated gitignore" from this commit.
回答1:
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.
回答2:
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.
回答3:
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.
来源:https://stackoverflow.com/questions/28624782/accidental-commit-how-to-not-push-an-unpushed-commit-in-magit-emacs