jjzjj

GitPython

全部标签

python - 如何使用 GitPython 获取暂存文件?

我正在使用GitPython计算git中的暂存文件.对于修改过的文件,我可以使用repo=git.Repo()modified_files=len(repo.index.diff(None))但是对于暂存文件我找不到解决方案。我知道gitstatus--porcelain但我正在寻找其他更好的解决方案。(我希望使用gitpython而不是git命令,脚本会更快) 最佳答案 你很接近,使用repo.index.diff("HEAD")获取暂存区中的文件。完整演示:首先创建一个测试仓库:$cdtest$mkdirrepo&&cdrepo

python - 如何使用 GitPython checkout 分支

我已经使用GitPython克隆了一个存储库,现在我想checkout一个分支并使用该分支的内容更新本地存储库的工作树。理想情况下,我还可以在执行此操作之前检查分支是否存在。这是我目前所拥有的:importgitrepo_clone_url="git@github.com:mygithubuser/myrepo.git"local_repo="mytestproject"test_branch="test-branch"repo=git.Repo.clone_from(repo_clone_url,local_repo)#Checkoutbranchtest_branchsomehow

python - 如何使用 GitPython checkout 分支

我已经使用GitPython克隆了一个存储库,现在我想checkout一个分支并使用该分支的内容更新本地存储库的工作树。理想情况下,我还可以在执行此操作之前检查分支是否存在。这是我目前所拥有的:importgitrepo_clone_url="git@github.com:mygithubuser/myrepo.git"local_repo="mytestproject"test_branch="test-branch"repo=git.Repo.clone_from(repo_clone_url,local_repo)#Checkoutbranchtest_branchsomehow

python - git log --follow,gitpython方式

我正在尝试访问单个文件的提交历史,如下所示:gitlog--follow--我必须使用gitpython,所以我现在要做的是:importgitg=git.Git('repo_dir')hexshas=g.log('--pretty=%H','--follow','--',filename).split('\n')然后我构建提交对象:repo=git.Repo('repo_dir')commits=[repo.rev_parse(c)forcinr]有没有办法以更gitpython-ic的方式做到这一点?我尝试了commit.iter_parents()和commit.iter_ite

python - git log --follow,gitpython方式

我正在尝试访问单个文件的提交历史,如下所示:gitlog--follow--我必须使用gitpython,所以我现在要做的是:importgitg=git.Git('repo_dir')hexshas=g.log('--pretty=%H','--follow','--',filename).split('\n')然后我构建提交对象:repo=git.Repo('repo_dir')commits=[repo.rev_parse(c)forcinr]有没有办法以更gitpython-ic的方式做到这一点?我尝试了commit.iter_parents()和commit.iter_ite

python - GitPython——如何对 GitPython 存储库进行 'git stash' 更改?

我有一个通过GitPython库创建的存储库,其中有一些未提交的更改。我想stash这些更改。我该怎么做?在GitPython中搜索“stash”docs没有返回任何结果。 最佳答案 根据文档,"Usinggitdirectly":Incaseyouaremissingfunctionalityasithasnotbeenwrapped,youmayconvenientlyusethegitcommanddirectly.Itisownedbyeachrepositoryinstance.因此,您可以调用gitstashsavere

python - GitPython 列出受某个提交影响的所有文件

我正在使用这个for循环遍历所有提交:repo=Repo("C:/Users/shiro/Desktop/lucene-solr/")forcommitinlist(repo.iter_commits()):printcommit.files_list#howtodothat?我如何获得受此特定提交影响的文件列表? 最佳答案 尝试一下forcommitinlist(repo.iter_commits()):commit.stats.files 关于python-GitPython列出受某

python - GitPython 创建和推送标签

在python脚本中,我尝试创建一个标签并将其推送到git存储库上的origin。我使用gitpython-1.0.2。我能够检查现有标签,但无法找到如何将新标签推送到远程。非常感谢 最佳答案 new_tag=repo.create_tag(tag,message='Automatictag"{0}"'.format(tag))repo.remotes.origin.push(new_tag) 关于python-GitPython创建和推送标签,我们在StackOverflow上找到一个

python - 使用 GitPython 模块获取远程 HEAD 分支

我正在尝试使用GitPython编写一些Python脚本,我可以用它来简化我管理许多分支的日常任务。在编写复杂脚本方面,我对Python还是个新手。这是我使用的API:GitPythonAPIdoc我想在GitPython中编写它,只需执行以下操作并解析出显示HEAD远程分支指向的部分。换句话说,我想基本上得到remotes/origin/HEAD$gitbranch-amaster*branch_to_removeremotes/origin/HEAD->origin/masterremotes/origin/masterremotes/origin/testing我多次浏览API文

python - 使用 gitpython 获取更改的文件

我想获取当前git-repo的更改文件列表。调用gitstatus时,通常在Changesnotstagedforcommit:下列出的文件。到目前为止,我已经成功连接到存储库,拉取它并显示所有未跟踪的文件:fromgitimportReporepo=Repo(pk_repo_path)o=self.repo.remotes.origino.pull()[0]print(repo.untracked_files)但现在我想显示所有有更改(未提交)的文件。有人能把我推向正确的方向吗?我查看了repo的方法名,试验了一段时间,没有找到正确的解决方案。显然我可以调用repo.git.stat