Find which revision is exported from

I have a source directory. There is a repository with this project, but there is no metadata or any manual report on which version it is based on in the catalog under consideration. How can I find which version is closest (there may be some modifications that have never been tested)?

+4
source share
4 answers

Inspired by the eckes suggestion , I cracked the following shell script:

#!/bin/sh

if [ "$#" -lt 1 ]; then
    echo "Usage: $0 path-to-export [rev-list-options...]"
    exit 1
fi

alt_work_tree=$1
shift

git rev-list "$@" | {
    min_changes=$(git --work-tree="$alt_work_tree" status --porcelain | wc -l)
    closest_revs=$(git rev-parse HEAD)
    lines=0

    while read revision; do
    git checkout -q "$revision"
    n_changes=$(git --work-tree="$alt_work_tree" status --porcelain | wc -l)
    if [ "$n_changes" -lt "$min_changes" ]; then
        min_changes=$n_changes
        closest_revs=$revision
    elif [ "$n_changes" -eq "$min_changes" ]; then
        closest_revs="$closest_revs $revision"
    fi
    lines=$((lines + 1))

    printf "rev: %s n: %s min_changes: %s   \r" "$revision" "$lines" "$min_changes"
    done

    echo
    echo "Number of changes left: $min_changes"
    echo "Possible revisions: $closest_revs"
    echo "Checking out: ${closest_revs%% *}"
    git checkout -q "${closest_revs%% *}"
}

In one case, I tried to find a fix that matches, in the other case it found something that makes sense, and there was no exact match, so I think it is doing its job.

script , , . git status .

, .

+2

.

git cat-file commit HEAD .

SHA1.

, git ls-tree HEAD , .

+1

, :

  • --work-tree ,
  • , .
+1

, git bisect :

  • bisecting, git bisect bad
  • claim that the first commit in the repo will be git bisect good
  • now, halving will present you with the changes for halving
  • for each step, enter git status --work-tree=/path/to/your/sources
    • If you have few differences, claim that this version will be good.
    • If you have a lot of disagreements, claim that this version is bad.
0
source

All Articles