admin管理员组文章数量:1334704
When git working tree is in conflict state during merge/rebase/cherry-pick, it's possible to get ours/theirs/base version of individual files by several ways, e.g. git checkout --ours/--theirs path/file
or git show :n:path/file
where n is 1, 2 or 3, see e.g. Git: get ours/theirs file content during merge
However, I would like to get ours and theirs commit hashes (SHA). For ours it's simple: git rev-parse HEAD
. But for theirs I have to try git rev-parse
for preudorefs MERGE_HEAD, REBASE_HEAD, CHERRY_PICK_HEAD, REVERT_HEAD, ...
(...
is for maybe more pseudorefs? E.g. what pseudoref has stash pop
conflict?). Is there any simple way to get theirs commit hash for all scenarios simply and reliably?
When git working tree is in conflict state during merge/rebase/cherry-pick, it's possible to get ours/theirs/base version of individual files by several ways, e.g. git checkout --ours/--theirs path/file
or git show :n:path/file
where n is 1, 2 or 3, see e.g. Git: get ours/theirs file content during merge
However, I would like to get ours and theirs commit hashes (SHA). For ours it's simple: git rev-parse HEAD
. But for theirs I have to try git rev-parse
for preudorefs MERGE_HEAD, REBASE_HEAD, CHERRY_PICK_HEAD, REVERT_HEAD, ...
(...
is for maybe more pseudorefs? E.g. what pseudoref has stash pop
conflict?). Is there any simple way to get theirs commit hash for all scenarios simply and reliably?
1 Answer
Reset to default 2Is there any simple way to get theirs commit hash for all scenarios simply and reliably?
There's no requirement that there be a commit hash for it. Git will already construct a base version from multiple merge bases resolving merges that have them, it's already common in some workflows to have a :1:$path
revision that's referenced only in the index, that was constructed specially.
Also: anyone doing something Git doesn't already have a convenience command for can load the index arbitrarily (pretty much the same way the existing conveniences do) with git update-index --index-info
or --cacheinfo
or --info-only
.
You could ls `git rev-parse --git-dir`/*_HEAD
and ignore FETCH_HEAD to get all the _HEAD
s of commands that follow the existing naming convention, and walk through their content looking for a match.
path=example.c
pathrev=`git rev-parse :3:$path`
for head in `git rev-parse --git-dir`/*_HEAD
do if test x`git rev-parse ${head##*/}:$path 2>&-` = x$pathrev
then git rev-parse ${head##*/}
fi; done
will do it for existing commands.
本文标签: git merge conflictGit get theirs commit hashStack Overflow
版权声明:本文标题:git merge conflict - Git get theirs commit hash - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742367553a2461594.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
-s --format=%H
togit-show
to get just the oid. – William Pursell Commented Nov 20, 2024 at 12:32git show :n:path/file
to show file content. I can get file oid bygit rev-parse :n:path/file
, but I want commit oid, see the question. – xmedeko Commented Nov 20, 2024 at 13:18