简化git存储库快照加载的python模块
gitsnapshot的Python项目详细描述
gitsnapshot
加载git存储库快照的简单库。
用法
加载git存储库调用load_repo
,如下所示:
fromgitsnapshotimportload_repoload_repo('~/target/directory','git@github.com/test/repo')<此代码创建文件夹^ {< CD2>},如果该文件夹不存在,则 克隆存储库的浅层副本
git@github.com/test/repo
。
默认情况下,此函数加载当前分支。要加载另一个分支(即develop
),请在branch
参数中传递分支名称:
fromgitsnapshotimportload_repoload_repo('~/target/directory','git@github.com/test/repo',branch='develop')
也可以按标记加载快照:
fromgitsnapshotimportload_repoload_repo('~/target/directory','git@github.com/test/repo',tag='v0.1.2')
或者通过提交哈希:
fromgitsnapshotimportload_repoload_repo('~/target/directory','git@github.com/test/repo',commit='abcdef')
错误
load_repo
函数返回带有错误描述的可选字符串。
如果load_repo
返回None
,则不会发生错误。
重新使用目录
如果尝试将存储库快照加载到现有目录中的另一个快照中 对于同一存储库,load_repo
将返回错误。
若要避免此行为,请将use_existing=True
作为参数传递。fromgitsnapshotimportload_repoload_repo('~/target/directory','git@github.com/test/repo',use_existing=True)
在这种情况下,load_repo
将加载存储库索引并签出到指定的
分支、标记或提交。