使用 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;
}
我应该使用相同的代码将未跟踪的文件添加到索引吗?