GitPython

remove a remote branch (push origin ':' ) with gitpython

隐身守侯 提交于 2021-02-10 16:18:59
问题 I cannot find a way to perform a commend equivalent to: git push origin :branchName A command that delete a remote branch, can gitpython perform this using git push? Thanks 回答1: I found the solution by myself, it is something like this: # repo is a local repository previously checked-out remote = repo.remote(name='origin') remote.push(refspec=(':delete_me')) 回答2: I was struggling with this as well so I'm posting this here for future posterity. One thing that I was missing was the need to

Python script to git clone without entering a password at the prompt

那年仲夏 提交于 2021-02-10 15:52:33
问题 I am trying to clone a project from the private git repository git clone gitolite@10.10.10.55:/Intel/BareRepos/lteue.git using the Python script. The problem with my script is I need to enter the password manually every time for cloning the project from local repository. Is there any pythonic way to clone the project without entering any password manually? This is the script which I had written. import os path = path/to/save/cloned/project os.chdir(path) os.system("git clone gitolite@10.10.10

How to get file data from a specific git commit using gitpython

守給你的承諾、 提交于 2021-02-10 14:24:31
问题 I am trying get a file from a specific commit using gitpython python-module. I'm able to get the file (with content) from the latest commit. However I want to get the file (with content) from a specific previous git commit. repo = git.Repo("G:\myrespo") obj = repo.git.get_object_data(x.a_blob) How can I get it ? 回答1: Here's one way to get a file from a specific commit: import io repo = Repo('G:\myrespo') # Retrieve specific commit from repo # The revision specifier must be one of the

How to get file data from a specific git commit using gitpython

别等时光非礼了梦想. 提交于 2021-02-10 14:23:02
问题 I am trying get a file from a specific commit using gitpython python-module. I'm able to get the file (with content) from the latest commit. However I want to get the file (with content) from a specific previous git commit. repo = git.Repo("G:\myrespo") obj = repo.git.get_object_data(x.a_blob) How can I get it ? 回答1: Here's one way to get a file from a specific commit: import io repo = Repo('G:\myrespo') # Retrieve specific commit from repo # The revision specifier must be one of the

GitPython List all commits for a specific file

≡放荡痞女 提交于 2021-02-08 11:13:09
问题 I am writing a Python script and there I need to know all commits for a specific file. In my code I use GitPython for other tasks but for this problem I can't find something. In cmd line I use: git log --pretty='%H' file-path 回答1: You can query the commits on the 'repo' that you cloned: commits = repo.iter_commits('--all', max_count=100, since='10.days.ago', paths=path) ...whereby '-all' will return commits on all branches and tags, and path is your filename. And to use the commits you go

How to download single file from a git repository using python

冷暖自知 提交于 2021-02-07 13:31:45
问题 I want to download single file from my git repository using python. Currently I am using gitpython lib. Git clone is working fine with below code but I don't want to download entire directory. import os from git import Repo git_url = 'stack@127.0.1.7:/home2/git/stack.git' repo_dir = '/root/gitrepo/' if __name__ == "__main__": Repo.clone_from(git_url, repo_dir, branch='master', bare=True) print("OK") 回答1: Don't think of a Git repo as a collection of files, but a collection of snapshots. Git

How to download single file from a git repository using python

吃可爱长大的小学妹 提交于 2021-02-07 13:30:19
问题 I want to download single file from my git repository using python. Currently I am using gitpython lib. Git clone is working fine with below code but I don't want to download entire directory. import os from git import Repo git_url = 'stack@127.0.1.7:/home2/git/stack.git' repo_dir = '/root/gitrepo/' if __name__ == "__main__": Repo.clone_from(git_url, repo_dir, branch='master', bare=True) print("OK") 回答1: Don't think of a Git repo as a collection of files, but a collection of snapshots. Git

git log --follow, the gitpython way

♀尐吖头ヾ 提交于 2021-02-05 18:17:04
问题 I am trying to access the commit history of a single file as in: git log --follow -- <filename> I have to use gitpython, so what I am doing now is: import git g = git.Git('repo_dir') hexshas = g.log('--pretty=%H','--follow','--',filename).split('\n') then I build commit objects: repo = git.Repo('repo_dir') commits = [repo.rev_parse(c) for c in r] Is there a way to do it in a more gitpython-ic way? I tried both commit.iter_parents() and commit.iter_items() , but they both rely on git-rev-list

git log --follow, the gitpython way

瘦欲@ 提交于 2021-02-05 18:05:14
问题 I am trying to access the commit history of a single file as in: git log --follow -- <filename> I have to use gitpython, so what I am doing now is: import git g = git.Git('repo_dir') hexshas = g.log('--pretty=%H','--follow','--',filename).split('\n') then I build commit objects: repo = git.Repo('repo_dir') commits = [repo.rev_parse(c) for c in r] Is there a way to do it in a more gitpython-ic way? I tried both commit.iter_parents() and commit.iter_items() , but they both rely on git-rev-list

git log --follow, the gitpython way

白昼怎懂夜的黑 提交于 2021-02-05 17:59:00
问题 I am trying to access the commit history of a single file as in: git log --follow -- <filename> I have to use gitpython, so what I am doing now is: import git g = git.Git('repo_dir') hexshas = g.log('--pretty=%H','--follow','--',filename).split('\n') then I build commit objects: repo = git.Repo('repo_dir') commits = [repo.rev_parse(c) for c in r] Is there a way to do it in a more gitpython-ic way? I tried both commit.iter_parents() and commit.iter_items() , but they both rely on git-rev-list