0

libgit2 API では、追跡用にファイルを「追加」することと、変更されたファイルをステージング領域に追加することの間に違いはありますか?

これは、変更された追跡ファイルをステージングするために現在使用しているコードです。

int giterror = git_repository_index( &index, open_repo );
if( giterror != 0 )
{
    return giterror;
}

//  Refresh the index from disk to load the entries that may already be staged
giterror = git_index_read( index );
if( giterror != 0 )
{
    git_index_free( index );

    return giterror;
}


giterror = git_index_add_bypath( index, relativeFilePath );
if( giterror != 0 )
{
    git_index_free( index );

    return giterror;
}


// write updated index to disk - aka staging area
giterror = git_index_write( index );
if( giterror != 0 )
{
    git_index_free( index );

    return giterror;
}


// write the index of changes to a tree
git_oid rootTreetOID;
giterror = git_index_write_tree( &rootTreetOID, index );
if( giterror != 0 )
{
    git_index_free( index );

    return giterror;
}

同じコードを使用して、追跡されていないファイルをインデックスに追加する必要がありますか?

4

1 に答える 1

1

はい、そうすべきです。

git_index_add_bypath()ドキュメントには、 「ディスク上のファイルからインデックス エントリを追加または更新する」場合に、このメソッドを使用する必要があると記載されています。

このメソッドは、

  • 追跡されていないファイルをインデックスに追加する
  • ファイルの変更をステージングする
于 2013-04-02T15:43:32.157 に答える