与此问题类似,但我没有创建新文件,而是尝试从原点合并。Rugged::Repository
使用's创建新索引merge_commits
和新的合并提交后,git 将新文件(来自origin
)报告为已删除。
创建合并索引,
> origin_target = repo.references['refs/remotes/origin/master'].target
> merge_index = repo.merge_commits(repo.head.target, origin_target)
和一个新的合并提交,
> options = {
update_ref: 'refs/heads/master',
committer: {name: 'user', email: 'user@foo.com', time: Time.now},
author: {name: 'user', email: 'user@foo.com', time: Time.now},
parents: [repo.head.target, origin_target],
message: "merge `origin/master` into `master`"}
并确保使用合并索引中的树。
> options[:tree] = merge_index.write_tree(repo)
创建提交
> merge_commit = Rugged::Commit.create(repo, options)
检查我们的 HEAD 是否已更新:
> repo.head.target.tree
=> #<Rugged::Tree:16816500 {oid: 16c147f358a095bdca52a462376d7b5730e1978e}>
<"first_file.txt" 9d096847743f97ba44edf00a910f24bac13f36e2>
<"second_file.txt" 8178c76d627cade75005b40711b92f4177bc6cfc>
<"newfile.txt" e69de29bb2d1d6434b8b29ae775ad8c2e48c5391>
看起来不错。我在索引中看到了新文件。将其写入磁盘。
> repo.index.write
=> nil
...但 git 将新文件报告为已删除:
$ git st
## master...origin/master [ahead 2]
D newfile.txt
如何正确更新我的索引和工作树?