z0d*_*14c 2 python git bash shell gitpython
我是Python / Git newb,但是我正在尝试编写一个脚本,该脚本以两个分支或提交作为参数,并显示两个之间的更改文件列表,而不是常规diff附带的所有无关信息。
这是通过使用以下命令在bash脚本中完成的
git diff --name-only FIRSTBRANCH...SECONDBRANCH
Run Code Online (Sandbox Code Playgroud)
但是使用gitpython转换为Python脚本并不容易。如果有人知道如何执行此操作,那就太好了。
编辑:这是一些代码
user = str(sys.argv[1])
password = str(sys.argv[2])
currentBranch = str(sys.argv[3])
compBranch = str(sys.argv[4])
repo = Repo(directory)
currentCommit = repo.commit(currentBranch)
compCommit = repo.commit(compBranch)
diffed = repo.diff(currentBranch, compBranch)
Run Code Online (Sandbox Code Playgroud)
当我只想要更改文件列表时,print diff将返回所有diff详细信息
小智 6
这是在python中执行此操作的方法。
#Dif two branches, returns list
import git
def gitDiff(branch1, branch2):
format = '--name-only'
commits = []
g = git.Git('/path/to/git/repo')
differ = g.diff('%s..%s' % (branch1, branch2), format).split("\n")
for line in differ:
if len(line):
commits.append(line)
#for commit in commits:
# print '*%s' % (commit)
return commits
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4094 次 |
最近记录: |