How to find mergers in history done using the git merge -s ours option?

Incorrect use of the -s ours merge option when merging origin / development in local development significantly speeds up the work done since the last modification was developed. I manually found two instances of this in git history, deliberately looking at the history for files that I know were missing.

Is there a way to find all the commits that were made using the merge option "-s ours"?

I assume this is possible by comparing the merge with the parents and checking if the contents of only one parent were actually executed, but I don't know how to translate this theory into the git command. Which team do I even start with?

+4
source share
1 answer

TL DR (but not verified)

Like a shell script:

git rev-list --merges HEAD |
while read rev; do
    thistree=$(git rev-parse $rev^{tree})
    p1tree=$(git rev-parse $rev^1^{tree})
    if [ $thistree = $p1tree ]; then
        echo "commit $rev has the effect of -s ours"
    fi
done

Long

The immediate answer is no (but readable). The actual strategy used is not automatically recorded. (If the people doing all the mergers were very self-disciplined, maybe they wrote down this information in every merger message. According to your description of the problem, this clearly did not happen ....) But this is not necessarily an interesting problem anyway. Perhaps someone will create a merger that has an effect -s ourswithout actually using a strategy ours.

A more interesting question is the automatic search for mergers that affect -s ours, regardless of whether this option was used; and it is easily automated.

The task is reduced to:

  • : git rev-list.
  • , -s ours: ... , . ; .

, , git rev-list. git log, git rev-list , Git , , , , , .

, HEAD, , , , , . , --branches ( ) --all ( , , , , refs/stash ).

. - : --min-parents=2. , , , :

git rev-list --merges HEAD

, , , HEAD. ( . Think Like (a) Git.)

git rev-list - , rev-list, --merges ( ): , . , .

, , . -s ours , Git, ( ) , . , ( theirs -, , -s theirs), , , " ", , , .

:

  • : git diff ( ) .
  • , , . ; git diff , .

tree shell-script, , , Git, "read every commit hash":

while read rev; do ...; done

$rev.

$rev (a commit) :

git rev-parse $rev^{tree}

gitrevisions, - . :

thistree=$(git rev-parse $rev^{tree})

. , gitrevisions, ${rev}^1. , . , , :

p1tree=$(git rev-parse $rev^1^{tree})

, commit $rev -s ours, , -s ours, git show .

( ) .

+5

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


All Articles