Mercurial: Any way to “merge and discard changes”?

前端 未结 1 1769
夕颜
夕颜 2020-12-10 01:56

I have a graphlog that looks something like this:

(snip)
  | |
  | o    1) Other Dev: Commit
  | | \\
  o | |  2) Me: Commit
/ | | |
| | o |  3) Other Dev: C         


        
相关标签:
1条回答
  • 2020-12-10 02:07

    Yes. The internal:local builtin merge tool.

    $ hg merge 4 --tool internal:local
    

    Similarly there's internal:other that picks the other version of files as the merged version.

    Here's an example to clarify what's going on, start off with a repo with a single file:

    $ echo a >> a
    $ hg ci -Am.
    adding a
    $ echo a >> a
    $ hg ci -Am.
    

    Branch it and put a conflict in a:

    $ hg up 0
    1 files updated, 0 files merged, 0 files removed, 0 files unresolved
    $ echo b >> a
    

    Also add another file just in the merged in branch:

    $ echo b >> b
    $ hg ci -Am.
    adding b
    created new head
    

    Go back and merge the anonymous head:

    $ hg up 1
    1 files updated, 0 files merged, 1 files removed, 0 files unresolved
    $ hg merge 2 --tool internal:local
    1 files updated, 1 files merged, 0 files removed, 0 files unresolved
    (branch merge, don't forget to commit)
    

    Naturally at this point without the merge tool we'd get a conflict on a. But using the merge tool, we're telling Mercurial to take the version of the first parent on every file that the merged with cset has also touched.

    $ hg st
    M a
    M b
    $ cat a
    a
    a
    $ cat b
    b
    
    0 讨论(0)
提交回复
热议问题