Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Added a modified file in git index but the file is not changing to staged

Tags:

git

c

libgit2

I'm trying to add a file to index to create a commit with libgit2.

The repo and index are like that:

git_repository *repo;
git_index *my_repo_index;
git_repository_open(&repo, ".");
git_repository_index(&my_repo_index, repo);
git_index_add_bypath(my_repo_index,"a.txt");
//all functions are returning 0, or success.

The "a.txt" file already exists in the index and is a modified file.

Before the commit the file is under "Changes not staged for commit", and I thought that after that the file would be under "staged" like after I executed "git add a.txt" but that didn't happened.

Am I missing something?

like image 347
AndreDurao Avatar asked Dec 21 '13 19:12

AndreDurao


People also ask

Why does git say changes not staged for commit?

The “changes not staged for commit” message shows when you run the “git status” command and have a file that has been changed but has not yet been added to the staging area. This is not an error message, rather a notification that you have changed files that are not in the staging area or a commit.

How do I see changes to a staged file in git?

If your changes are already staged, then there's no difference to show. But there's a command line option that will show you staged changes if you specify it: git diff --staged . With the --staged option, git diff will compare your staged changes against the previous commit.


1 Answers

Changes to the index are not immediately written to disk. You might, for example, wish to perform a number of actions and save them all at once. In order to save the index:

git_index_write(my_repo_index);
like image 56
Edward Thomson Avatar answered Sep 21 '22 17:09

Edward Thomson