Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git commit from python

Tags:

git

python

I want to write a module in python (This is the learning project) to enhance my git experience. Is there a python module for various git commands? At least the basic ones (commit/diff/log/add)?

I saw GitPython but I couldn't find the support for (new) commits; its more of a repo browsing framework than a complete GIT interface. (Or did I miss something?)

Also, if there IS a python module for all this, will that be preferable, or executing the shell commands from python code?

like image 535
Sailesh Avatar asked Aug 19 '11 09:08

Sailesh


People also ask

What is git commit-m example?

Example git commit -m "First release of Hello World!" [master (root-commit) 221ec6e] First release of Hello World! 3 files changed, 26 insertions (+) create mode 100644 README.md create mode 100644 bluestyle.css create mode 100644 index.html The commit command performs a commit, and the -m " message " adds a message.

How to print the specific range of commit data in Git?

os module is used to read the absolute path of our git repository stored in our system i.e REPO_PATH variable we set earlier. COMMITS_TO_PRINT is a constant which is used to print the specific range of commit. Now create a function print_commit _data in the same file to print individual commit data:

How do I use Git in Python?

Let's look at some common tasks with Git and how to do them in Python. Initialize a new repository To start a new repository, you can use git.Repo.init () which is equivalent to running git init. import git # `git init new_repo` new_repo = git.Repo.init ('new_repo') This will create a new directory named new_repo with the .git directory.

How do I commit to a specific branch in Git?

Git Commit To commit indexed changes to a local branch in the local repo. import git repo.git.add ('--all') repo.git.commit ('-m', 'commit message from python script', author='[email protected]')


1 Answers

In GitPython you create a commit from an index object.

In libgit2 you create a commit from a repository object.

You might also want to look at this question:

  • Python Git Module experiences?
like image 71
Mark Longair Avatar answered Oct 11 '22 11:10

Mark Longair