How to stage changes with gitpython
Asked Answered
S

1

10

Does anyone know what the equivalent of git commit -a is in gitpython?

I have tried repo.index.commit, but don't see how to add the -a option. repo.index.add adds only new files, not existing files that have been modified. It doesn't seem to support the update function as in git add -u.

I could do something like repo.git.commit('-a'), or even

repo.git.add('-u')
repo.index.commit(comment)

But I would think the high-level interface should be capable of doing this. Am I missing something?

Thanks in advance,

Evert

Sennet answered 16/9, 2015 at 9:45 Comment(1)
i'm having the same issue, and below answer doesn't seem to help.Commodus
R
9

You are not missing anything. GitPython acts more like plumbing, not like the porcelain that is git add -u and git commit.

Therefore it is viable and recommended to use the provided git command wrapper to get work done quickly as already demonstrated in your example (e.g. repo.git.add(update=True)).

Even though it is possible to implement anything purely in GitPython, it wouldn't perform as well or be as proven as the respective native git implementation already is.

GitPython starts to become powerful if you want to access git repository data quickly and conveniently through a relatively convenient and pythonic API. Examples include accessing branch and tag information, or querying commits in all detail.

Rapid answered 17/9, 2015 at 6:3 Comment(1)
Sorry for the late reply, I noticed just now I forgot to thank you, @Byron. I appreciate the efforts in maintaining a library like gitpython, glad to better understand its philosophy. Thanks again!Sennet

© 2022 - 2024 — McMap. All rights reserved.