最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

git merge conflict - Git get theirs commit hash - Stack Overflow

programmeradmin0浏览0评论

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?

Share Improve this question edited Nov 22, 2024 at 14:16 xmedeko asked Nov 20, 2024 at 9:53 xmedekoxmedeko 7,8206 gold badges59 silver badges91 bronze badges 3
  • You can specify -s --format=%H to git-show to get just the oid. – William Pursell Commented Nov 20, 2024 at 12:32
  • @WilliamPursell It does not work with git show :n:path/file to show file content. I can get file oid by git rev-parse :n:path/file, but I want commit oid, see the question. – xmedeko Commented Nov 20, 2024 at 13:18
  • I am not aware of a function that would make this simple. You have to try all of them, or at least the one that pertains to the operation that caused the conflict. – j6t Commented Nov 20, 2024 at 13:24
Add a comment  | 

1 Answer 1

Reset to default 2

Is 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 _HEADs 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.

发布评论

评论列表(0)

  1. 暂无评论