简体   繁体   English

坚固耐用的(libgit2)索引阶段

[英]Rugged (libgit2) stage for index

Looking at index (following a call to merge_commits between master and a branch), I'm seeing 3 results for the same file, 查看索引(在master和分支之间调用merge_commits ),对于同一文件,我看到3个结果,

{:path=>"file.txt", :oid=>"c6fdbacd7400805042668f4ccf70fc1ebbdac361", :dev=>0, :ino=>0, :mode=>33188, :gid=>0, :uid=>0, :file_size=>0, :valid=>false, :stage=>1, :ctime=>1969-12-31 19:00:00 -0500, :mtime=>1969-12-31 19:00:00 -0500}
{:path=>"file.txt", :oid=>"0838a4be16d19278e1e549614ffd2b6759549185", :dev=>0, :ino=>0, :mode=>33188, :gid=>0, :uid=>0, :file_size=>0, :valid=>false, :stage=>2, :ctime=>1969-12-31 19:00:00 -0500, :mtime=>1969-12-31 19:00:00 -0500}
{:path=>"file.txt", :oid=>"4bd2639f786bef1000dad7d59c6779a4e99fb27c", :dev=>0, :ino=>0, :mode=>33188, :gid=>0, :uid=>0, :file_size=>0, :valid=>false, :stage=>3, :ctime=>1969-12-31 19:00:00 -0500, :mtime=>1969-12-31 19:00:00 -0500}

My understanding by looking at the content of each of these is that stage 3 is the most "recent/advanced" change, but can someone explain the concept behind these stages and the numbering? 通过查看每个阶段的内容,我的理解是,阶段3是最“最近/高级”的更改,但是有人可以解释这些阶段和编号背后的概念吗? And stage 0 is missing because there are changes in this file that are uncommited? 缺少阶段0,因为此文件中有未提交的更改吗?

I'm not familiar with libgit2, but nonzero stages in git index files are meant for dealing with merge conflicts. 我对libgit2不熟悉,但是git索引文件中的非零阶段用于处理合并冲突。

Until the conflict is resolved, there will be up to three entries for a single path name, as described in the gitrevisions documentation : 在解决冲突之前,单个路径名最多包含三个条目,如gitrevisions文档中所述

A colon, optionally followed by a stage number (0 to 3) and a colon, followed by a path, names a blob object in the index at the given path. 冒号(可选后跟阶段号(0到3))和冒号(后跟路径)在给定路径的索引中命名blob对象。 A missing stage number (and the colon that follows it) names a stage 0 entry. 缺少的阶段号(及其后的冒号)将命名为阶段0条目。 During a merge, stage 1 is the common ancestor, stage 2 is the target branch's version (typically the current branch), and stage 3 is the version from the branch which is being merged. 在合并过程中,阶段1是公共祖先,阶段2是目标分支的版本(通常是当前分支),阶段3是要合并的分支的版本。

If the merge conflict is because of a deletion (ie, file existed in common ancestor but is missing from one branch and modified in the other), there will be only one of stage 2 or 3; 如果合并冲突是由于删除(例如,文件存在于共同祖先中,但在一个分支中丢失而在另一个分支中被修改),则只有阶段2或3中的一个阶段; if it is because of a creation (file did not exist in common ancestor but was created in both branches) there will be no stage 1 entry. 如果是由于创建(文件在共同祖先中不存在,而是在两个分支中都已创建),则将没有阶段1条目。 (I'm not sure I have covered all cases of fewer-than-3 entries here.) (我不确定这里是否涵盖了所有少于3个条目的案例。)

Before you can finish and commit the merge, you must replace the nonzero stage entries with a single stage-0 entry. 在完成并提交合并之前,必须用一个0级条目替换非零级条目。

When you do a merge, git needs the changes at each tip from the base version. 合并时,git需要在基本版本的每个技巧上进行更改。 The index records the base version id and each tips version oid, as 1 (the base) 2 ("ours"), 3 ("theirs"). 索引记录基本版本id和每个提示版本oid,分别为1(基本)2(“我们的”)和3(“其”)。 Recording the content id's allows you to rerun the diffs under various options (eg to get 3-diff conflict reporting or to ignore whitespace changes) as needed. 记录内容ID可使您根据需要在各种选项下重新运行差异(例如,获取3-diff冲突报告或忽略空白更改)。 Stage 0 is for resolved content, content with no inflight merge. 阶段0用于解析的内容,没有进行中合并的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM