Home > Blockchain >  Why "theirs" tactic not working here when I am in merging state?
Why "theirs" tactic not working here when I am in merging state?

Time:10-19

We can reproduce this problem by:

  1. Setup
    git remote add proxy [email protected]:pingcap/tidb-engine-ext.git
    git remote add tikv [email protected]:tikv/tikv.git
    git fetch proxy 3f55709e6678c687195fbbd59662459aa348d039
    git fetch tikv b448214b8f2c0a6a9ba2381a1983ce20e6514218
    
  2. Merge tikv's commit b4482 into proxy at 3f557
    git checkout -b test 3f55709e6678c687195fbbd59662459aa348d039
    git merge b448214b8f2c0a6a9ba2381a1983ce20e6514218
    

There are many unrelavant conflicts, so just don't look at them. We only look into components/resolved_ts/src/endpoint.rs at line 502, it says

let resolved_ts = observe_region.resolver.resolve(ts).min();

However, "theirs" version is

let resolved_ts = observe_region.resolver.resolve(ts);

Now, I decide to replace the whole file with "theirs", so I run

git checkout --theirs components/resolved_ts
Updated 1 path from the index

And then I find

let resolved_ts = observe_region.resolver.resolve(ts).min();

Yes, the file is not changed into "theirs". It is weird.

However, if I run

git checkout b448214b8f2c0a6a9ba2381a1983ce20e6514218 -- components/resolved_ts

The the file is changed into "theirs". It is more weird now. Since if this works, why git checkout --theirs fails?

Can anyone tell me why this happens?

My toolchain is

git --version
git version 2.30.1 (Apple Git-130)

CodePudding user response:

If you inspect the git merge output more closely, you will see the following:

Auto-merging components/resolved_ts/src/endpoint.rs
Auto-merging components/resolved_ts/src/cmd.rs

Compare this with, e.g.:

Auto-merging Makefile
CONFLICT (content): Merge conflict in Makefile
Auto-merging Cargo.toml
CONFLICT (content): Merge conflict in Cargo.toml

Note how, for each of the last two files, we see first:

Auto-merging

and then:

CONFLICT (content):

followed by the file's name. For endpoint.rs and cmd.rs, however, we see Auto-merging followed by ... nothing at all, indicating that the auto-merge worked.

If you inspect what's in the index, there's no "theirs" version left behind:

$ git ls-files --stage components/resolved_ts/src/endpoint.rs
100644 a4e5f6e38641e12820167e715e8666b844943f40 0  components/resolved_ts/src/endpoint.rs

Similarly, git status --short shows:

$ git status --short | grep components/resolved_ts/
M  components/resolved_ts/src/cmd.rs
UU components/resolved_ts/src/resolver.rs
M  components/resolved_ts/tests/mod.rs

Note that endpoint.rs is not in this list: there was a conflict, but it was easily auto-resolved, and Git not only resolved it, but invoked git add on the result. That's why --theirs does nothing: there is no "theirs" version in the index. The one matching components/resolved/ path that does have a theirs version in the index—which is where:

Updated 1 path from the index

came from above—is UU components/resolved_ts/src/resolver.rs.

  •  Tags:  
  • git
  • Related