Git conflict with merging submodules: how to visualize?

I was very pleased when I found out recently about

git submodule summary 

which shows me well, with the help of which a fixed submodule fixer is in front of or behind the link in the repository.

Now that I'm in the middle of merging conflicts with submodules, this same command does not provide a useful conclusion. I need a painful gitk sequence in my main tree exploring branches, as well as cd'ing in submodules, fetching and gitk there, comparing sha1 values ​​...

What would be a more convenient way to get a picture of the conflict?

+6
source share
2 answers

You can create a script. Here is the core of such a script:

  git --git-dir=submodulepath/.git diff \ $(git ls-tree HEAD submodulepath | cut -c 15-54) \ $(git ls-tree MERGE_HEAD submodulepath | cut -c 15-54) 

you can replace diff with a log or any number of other commands to help you see what the changes are. One could see if this will be a quick merger, in which case you can quickly resolve the conflict without merging at the submodule level.

There is also a gitslave that will help you solve such problems.

Hope this helps.

+2
source

Same as Adam's answer , but using an index and without a cut:

 sub="path/to/submodule" git --git-dir="$sub/.git" diff \ $(git rev-parse ":2:$sub") \ $(git rev-parse ":3:$sub") 

Explanation:

When there is a conflict, Git stores information about this in the index. It stores several different versions, the so-called stages. Stage 1 is the "basic" version (common ancestor), stage 2 is the "our" version, and stage 3 is the "their" version.

In case of file conflicts, the index contains blob object identifiers for different versions. In the case of submodules, these are identifiers for fixing the submodule. In the command above :2:$sub refers to step 2 (ours) of the submodule in the path of $sub .

Note that you can see a list of index entries with steps with git ls-files --stage .

0
source

Source: https://habr.com/ru/post/890074/


All Articles