How do I force git to think a file is unmerged?

前端 未结 1 1097
花落未央
花落未央 2020-12-05 16:28

I want to make changes to a file in my repo, then force git to believe the file is unmerged and show up in git status like so:

# Unmerged paths:         


        
相关标签:
1条回答
  • 2020-12-05 17:04

    In Git file that has a merge conflicts has (usually) three versions in index, and a version in working area with diff3 -E / rcsmerge conflict markers. The versions in the index are stage 1 from common ancestor, stage 2 for "our" version, and stage 3 for "theirs" version. For unmerged file there is no version in stage 0 (you can use git update-index --unresolve to restore unmerged state by deleting stage 0).

    You would need to use git ls-files --stage or git ls-tree <commit> to get sha-1 identifiers of blobs (file versions) you want to put in index, or git hash-object -w <file> if you want to generate version of a file from scratch / from working area version. Then you use git update-index --index-info to put higher order stages into the index file (and git update-index --unresolve after this, or git update-index --force-remove prior to stuffing higher stages to remove stage 0 from index). You can re-generate file with merge markers in working area using git checkout --conflict=merge -- <file>.

    HTH (Hope That Helps)


    See also: "How to selectively recreate merge state?" thread on Git mailing list.

    0 讨论(0)
提交回复
热议问题