Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9116977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:48:03+00:00 2026-06-17T04:48:03+00:00

I use git_index_add_from_workdir to add, but why git_index_entrycount return 0? and another question, I

  • 0

I use git_index_add_from_workdir to add, but why git_index_entrycount return 0?
and another question, I clone a git from remote, and git_index_entrycount also return 0?
Why?
below is the code that how I got the IndexCount , I first create a new repo, and create new file and document

(IBAction)IndexInfo:(id)sender {    
git_index *index = NULL;
int ret = 0 ;
char out[41];
out[40] = '\0';
NSArray *array = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *docPath = [array objectAtIndex:0];
NSString *dir = [docPath stringByAppendingPathComponent:@"efg/" ];
NSLog(@"dir:%@",dir);

git_repository *repo = NULL;
ret = git_repository_init(&repo, [dir UTF8String], 0);
NSLog(@"git_repository_init ret:%d", ret);
git_repository_index(&index, repo);
if(git_index_entrycount(index) == 0)
{
    NSLog(@"initial ok");
}
NSString *testPath = [dir stringByAppendingPathComponent:@"test00.txt"];
NSString *string = @"write String";
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL bres = [fileManager createFileAtPath:testPath contents:[string  dataUsingEncoding:NSUTF8StringEncoding] attributes:nil];
if(bres == NO)
{
    NSLog(@"create file error.");
}
ret = git_index_add_from_workdir(index, "test00.txt");
NSLog(@"git_index_add_from_workdir ret:%d", ret);

ret = git_index_read(index);
NSLog(@"index_read ret:%d", ret);

int ecount = git_index_entrycount(index);
if (!ecount)
    printf("Empty index\n");
NSLog(@"index ecount:%d",ecount);
for (int i = 0; i < ecount; ++i) {
    const git_index_entry *e = git_index_get_byindex(index, i);

    git_oid_fmt(out, &e->oid);

    printf("File Path: %s\n", e->path);
    printf("    Stage: %d\n", git_index_entry_stage(e));
    printf(" Blob SHA: %s\n", out);
    printf("File Mode: %07o\n", e->mode);
    printf("File Size: %d bytes\n", (int)e->file_size);
    printf("Dev/Inode: %d/%d\n", (int)e->dev, (int)e->ino);
    printf("  UID/GID: %d/%d\n", (int)e->uid, (int)e->gid);
    printf("    ctime: %d\n", (int)e->ctime.seconds);
    printf("    mtime: %d\n", (int)e->mtime.seconds);
    printf("\n");
}

git_index_free(index);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:48:04+00:00Added an answer on June 17, 2026 at 4:48 am

    git_index_add_from_workdir() updates the in-memory instance of the index. The change isn’t persisted on the filesystem (in order to make this happen, one would have to call git_index_write()).

    Calling git_index_read() updates the in-memory index with what is being stored on the filesystem and thus discards any “unsaved” change. This explains why you end up with an entrycount of zero entry.

    In order to fix this, either remove the call to git_index_read() or add a call to git_index_write() before the call to git_index_read().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use git on windows to clone a remote repository. I can
Git says to use git add to add untracked files to my repo. I
I'm trying to use git add --interactive to selectively add some changes to my
I am trying to use the Store Locator plugin from google developer: http://storelocator.googlecode.com/git/index.html?utm_campaign=sl&utm_source=youtube I
I used git add -p to split my code changes into multiple commits. However,
D:\code\gt>git init Initialized empty Git repository in D:/code/gt/.git/ D:\code\gt>echo Zero > a D:\code\gt>git add
(Predominantly a Git question, but may be relevant to other PyroCMS users) I have
Is it possible to configure Git to use my configured difftool with git add
I use git to manage my dotfiles, I use both linux and mac osx
I use git svn to track a SVN repo. When I try to do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.