Is there any way to delete local commits in Mercurial?

后端 未结 10 1001
小鲜肉
小鲜肉 2020-11-28 19:11

So I keep making a silly mistake in Mercurial. Often times, I\'ll start work without doing an \"hg pull\" and an \"hg update.\" When I try to push my changes, I get an err

相关标签:
10条回答
  • 2020-11-28 19:42

    Modern answer (only relevant after Mercurial 2.1):

    Use Phases and mark the revision(s) that you don't want to share as secret (private). That way when you push they won't get sent.

    In TortoiseHG you can right click on a commit to change its phase.

    Also: You can also use the extension "rebase" to move your local commits to the head of the shared repository after you pull.

    0 讨论(0)
  • 2020-11-28 19:45

    If you are familiar with git you'll be happy to use histedit that works like git rebase -i.

    0 讨论(0)
  • 2020-11-28 19:46

    As everyone else is pointing out you should probably just pull and then merge the heads, but if you really want to get rid of your commits without any of the EditingHistory tools then you can just hg clone -r your repo to get all but those changes.

    This doesn't delete them from the original repository, but it creates a new clone that doesn't have them. Then you can delete the repo you modified (if you'd like).

    0 讨论(0)
  • 2020-11-28 19:47

    You can get around this even more easily with the Rebase extension, just use hg pull --rebase and your commits are automatically re-comitted to the pulled revision, avoiding the branching issue.

    0 讨论(0)
  • 2020-11-28 19:49

    If you are using Hg Tortoise just activate the extension "strip" in:

    1. File/Settings/Extensions/
    2. Select strip

    Then select the bottom revision from where you want to start striping, by doing right click on it, and selecting:

    1. Modify history
    2. Strip

    Just like this:

    enter image description here

    In this example it will erase from the 19th revision to the last one commited(22).

    0 讨论(0)
  • 2020-11-28 19:50

    [Hg Tortoise 4.6.1] If it's recent action, you can use "Rollback/Undo" action (Ctrl+U).

    0 讨论(0)
提交回复
热议问题