Felczer
Felczer

Reputation: 1

How to replicate 'git rm --cached' in libgit2

I've been trying to replicate git rm --cached in libgit2. In Git, this command will remove the file in changes to be committed without removing the file from local disk.

I tried to use the git_index_remove_bypath(idx, path) command, however, it does not seem to be working. The command does not return any errors, nor does opening the repo or index.

After using this command on a file the status of the file changes to unknown, however, after doing git status, the file does not seem to have any changes to commit.

I expect result after using the command: changes to be committed — file deleted and file untracked.

Code example:

int errorCode = git_repository_index(&idx, _repo); //repo initialized elsewhere
errorCode = git_index_remove_bypath(idx, path.c_str());

Upvotes: 0

Views: 61

Answers (0)

Related Questions