@@ -929,6 +929,11 @@ if (git_index_has_conflicts(idx)) {
929
929
<h3 id =" index_add " >Add & Remove</h3 >
930
930
931
931
``` c
932
+ /* Force a single file to be added (even if it is ignored) */
933
+ error = git_index_add_bypath(idx, " path/to/file.py" );
934
+ /* … or removed */
935
+ error = git_index_remove_bypath(idx, " path/to/file.py" );
936
+
932
937
typedef struct { /* … * / } match_data;
933
938
int match_cb(const char * path, const char * spec, void * payload)
934
939
{
@@ -943,7 +948,7 @@ int match_cb(const char *path, const char *spec, void *payload)
943
948
const char * paths[ ] = {"src/* ", "test/* "};
944
949
git_strarray arr = {paths, 2};
945
950
946
- /* Add matching files; this skips ignored files * /
951
+ /* Add matching files ( this skips ignored files) * /
947
952
match_data d = {0};
948
953
int error = git_index_add_all(idx, &arr, GIT_INDEX_ADD_DEFAULT,
949
954
match_cb, &d);
@@ -952,20 +957,15 @@ error = git_index_remove_all(idx, &arr, match_cb, &d);
952
957
953
958
/* Something like 'git add .' * /
954
959
error = git_index_update_all(idx, &arr, match_cb, &d);
955
-
956
- /* Force a single file to be added (even if it is ignored) * /
957
- error = git_index_add_bypath(idx, "path/to/file.py");
958
- /* …or removed * /
959
- error = git_index_remove_bypath(idx, "path/to/file.py");
960
960
```
961
961
962
962
(
963
+ [`git_index_add_bypath`](http://libgit2.github.com/libgit2/#HEAD/group/index/git_index_add_bypath),
964
+ [`git_index_remove_bypath`](http://libgit2.github.com/libgit2/#HEAD/group/index/git_index_remove_bypath),
963
965
[`git_strarray`](http://libgit2.github.com/libgit2/#HEAD/type/git_strarray),
964
966
[`git_index_add_all`](http://libgit2.github.com/libgit2/#HEAD/group/index/git_index_add_all),
965
967
[`git_index_remove_all`](http://libgit2.github.com/libgit2/#HEAD/group/index/git_index_remove_all),
966
- [`git_index_update_all`](http://libgit2.github.com/libgit2/#HEAD/group/index/git_index_update_all),
967
- [`git_index_add_bypath`](http://libgit2.github.com/libgit2/#HEAD/group/index/git_index_add_bypath),
968
- [`git_index_remove_bypath`](http://libgit2.github.com/libgit2/#HEAD/group/index/git_index_remove_bypath)
968
+ [`git_index_update_all`](http://libgit2.github.com/libgit2/#HEAD/group/index/git_index_update_all)
969
969
)
970
970
971
971
0 commit comments