Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stage changes with gitpython

Tags:

gitpython

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

like image 235
EvertW Avatar asked Sep 16 '15 09:09

EvertW


People also ask

What does it mean to stage a change in git?

To stage a file is simply to prepare it finely for a commit. Git, with its index allows you to commit only certain parts of the changes you've done since the last commit.


1 Answers

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.

like image 166
Byron Avatar answered Oct 08 '22 15:10

Byron