【问题标题】:where is the last commit <SHA-1> of subtree repo is stored locally子树 repo 的最后一次提交 <SHA-1> 在哪里存储在本地
【发布时间】:2016-05-25 23:21:49
【问题描述】:

他们说

git-subtree 存储子项目提交 ID,而不是元数据中的引用。

意思是命令

git subtree add --prefix some-split-sub-directory https://some-other-repo-url master --squash

将主 HEAD 的 SHA-1 存储在 git 管理的元数据信息中的某个位置 https://some-other-repo-url

现在当我下次运行以下命令时

git subtree pull --prefix some-split-sub-directory https://some-other-repo-url master --squash

git 知道 URL https://some-other-repo-url 上最后一次提交的 SHA-1,它已合并到根/父项目中,现在它会获取/合并最后一次提交 SHA-1 之外的代码/提交。

现在我的问题是,last-commit-of-subtree 的信息存储在本地 .git 文件夹中的什么位置?

我怎么能看到这是针对这个 repo 存储的最后一次提交 SHA-1 并且高于/超出下一次拉/合并将发生?

我曾窥视过以下地方,例如 .git/config、.git/refs,但没有找到任何信息。

【问题讨论】:

    标签: git git-subtree


    【解决方案1】:

    我在 .git 文件夹中也找不到它,但我设法使用以下函数获取它: https://github.com/git/git/blob/master/contrib/subtree/git-subtree.sh

    AFAICT 它解析 git 历史以获取最新的相关子树壁球:

    find_latest_squash () {
        debug "Looking for latest squash ($dir)..."
        dir="$1"
        sq=
        main=
        sub=
        git log --grep="^git-subtree-dir: $dir/*\$" \
            --no-show-signature --pretty=format:'START %H%n%s%n%n%b%nEND%n' HEAD |
        while read a b junk
        do
            debug "$a $b $junk"
            debug "{{$sq/$main/$sub}}"
            case "$a" in
            START)
                sq="$b"
                ;;
            git-subtree-mainline:)
                main="$b"
                ;;
            git-subtree-split:)
                sub="$(git rev-parse "$b^0")" ||
                die "could not rev-parse split hash $b from commit $sq"
                ;;
            END)
                if test -n "$sub"
                then
                    if test -n "$main"
                    then
                        # a rejoin commit?
                        # Pretend its sub was a squash.
                        sq="$sub"
                    fi
                    debug "Squash found: $sq $sub"
                    echo "$sq" "$sub"
                    break
                fi
                sq=
                main=
                sub=
                ;;
            esac
        done
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-29
      • 2011-10-31
      • 2020-04-04
      • 1970-01-01
      • 2015-08-09
      • 2020-11-05
      • 1970-01-01
      • 2021-08-07
      相关资源
      最近更新 更多