5

git リポジトリにファイルがあるとします。

  • a.txt

そのファイルを削除するコミットを作成するには、どの API を使用する必要がありますか? たとえば、この質問では、ファイルはディスク上に作成せずにコミットされます。インデックス (ステージ領域) を使用せずにそのファイルを削除することは可能ですか?

おそらくツリービルダー用の を作成するなど、同様のフローを期待していましたgit_tree_entryが、そうではないようです。git_reference_list()ファイルをリストしないため、行き止まりがあります。また、削除と削除のソースを検索しても成功しませんでした。

4

2 に答える 2

4

ファイルの削除は、ファイルの追加と似ています。インデックス エントリを削除して削除をステージングしてから、インデックスからコミットを作成できます。

おそらくgit_index_remove_bypath、ファイルをインデックスから削除し、ファイルの競合を解決するを使用することをお勧めします。

于 2013-03-29T22:59:45.790 に答える
0

以下はコピー&ペーストの例です。この質問getLastCommit()参照してください。

bool commitStage ( 
    git_repository * repo, git_signature * sign,
    const char * message )
{
  bool b = false;
  int rc;
  git_index * repo_idx;   /* the stage area for our repository */
  git_oid oid_idx_tree;   /* the SHA1 for the tree generated from index */
  git_oid oid_commit;     /* the SHA1 for our commit */
  git_tree * tree_cmt;    /* tree generated from index */
  git_commit * parent_commit;/* most recent commit in the head */

  parent_commit = getLastCommit( repo );
  if ( parent_commit != NULL )
  { /* we have the parent commit */
    rc = git_repository_index( &repo_idx, repo );
    if ( rc == 0 )
    { /* we now have the index (stage area) structure in repo_idx */
      git_index_read(repo_idx);
      /* the stage area may be altered here with functions like 
        git_index_add_bypath();
        git_index_remove_bypath();
        */

      /* by writing the index we get the SHA1 of the tree */
      rc = git_index_write_tree( &oid_idx_tree, repo_idx );
      if ( rc == 0 )
      {
        rc = git_tree_lookup(
              &tree_cmt, repo, &oid_idx_tree );
        if ( rc == 0 )
        { /* the actual tree structure; create a commit from it */
          rc = git_commit_create(
                &oid_commit, repo, "HEAD",
                sign, sign, NULL,
                message,
                tree_cmt, 1, (const git_commit**)&parent_commit );
          if ( rc == 0 )
          {
            b = true;
          }
        }
      }
      git_index_free( repo_idx );
    }
    git_commit_free( parent_commit );
  }
  return b;
}
于 2013-03-30T10:46:20.767 に答える