Abandoning changes without deleting from history

后端 未结 9 1994
再見小時候
再見小時候 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:16

    An alternative to closing or stripping the unwanted branch would be to merge it in a way that totally discards its effects, but leaves it in history. This approach will allow those unwanted changes to propagate in a push - so only use this if that is the intended effect.

    Let's say the changeset history looks like this:

    1-2-3-4-5-6    
           \    
            7-8-*
    

    and it is 5 and 6 which are no longer wanted.

    You can do this:

    hg up 8
    hg merge -r 6 -t :local
    hg commit ...
    

    which will create this:

    1-2-3-4-5-6    
           \   \
            7-8-9-*
    

    The update to 8 ensures you are working at the desired head in history, which you want to keep.

    The -t :local instructs hg to use the merge "tool" called local which tells it to ignore changes from the other branch, i.e., the one NOT represented by the current working folder state. More info.

    Thus the unwanted changes in 5 and 6 are preserved in history but do not affect anything more recent.

提交回复
热议问题