Abandoning changes without deleting from history

后端 未结 9 1954
再見小時候
再見小時候 2020-11-28 18:01

There is a commit that just didn\'t work, so I want to abandon it without deleting it from history.

I have updated from an earlier revision and committed, t

相关标签:
9条回答
  • 2020-11-28 18:30

    You may clone your corrupted repo to a new one without cloning that unwanted head. Then remove old repository, move newly created clone to the original place and continue working with it. This will take some time, but you'll get a perfectly clean repository without a sign of that unwanted revision.

    hg clone --rev myGoodResition myDirtyRepo myCleanRepo
    
    0 讨论(0)
  • 2020-11-28 18:32

    Both Niall's and Nick's answers are straight on. Because I find myself creating lots of dangling heads, I ended up writing an alias to close heads more easily. By adding this to your .hgrc:

    [alias]
    behead = !REV=$($HG id -i); $HG update $@ -q && $HG ci --close-branch -m "Closing dead head" && $HG update $REV -q
    

    (if you already have an [alias] section, you can append to it instead)

    You can now close a head in one single-command (and without having to update to a different changeset manually) like this:

    $ hg behead 123
    

    Note: the alias takes advantage of the fact that Mercurial aliases can be shell commands. This means that this will probably only work on UNIX, not on Windows.

    0 讨论(0)
  • 2020-11-28 18:35

    This is a use case for the Evolve extension. It's currently not bundled with Mercurial, so it is technically a third party extension. But it's being used quite heavily by a bunch of people, including Mercurial developers, is being very actively developed, and isn't going anywhere.

    With the Evolve extension, you simply do

    hg prune -r revname
    

    and get on with your life. The cset will still be there, but obsoleted. It won't be visible unless you pass the --hidden option to Mercurial commands, and by default won't be pushed to remote repositories. Though I think you can force it if you really want to.

    If the cset you are pruning has ancestors you want to keep, then you'll have to run hg evolve to rebase those changesets. hg evolve will do so automatically. Otherwise, you don't have to do anything.

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