我想分别访问任何存储库文件的密钥。
如您所见。有一个文件结构,其中包括一个我用gitpython创建的.git目录。我可以获取用于表示所有文件的存储库sha键;
from git import Repo
repo = Repo("graph/features")
master = repo.head.reference
print(master.commit.hexsha)
我的问题是,我想为任何文件(例如file2.txt)生成sha键。有什么方法可以实现这一点。抱歉,我是使用gitPython的新手。
答案 0 :(得分:1)
然后读取文件
...
<flow id="defaultFlow">
<step id="stepOne" next="stepTwo">
<chunk checkpoint-policy="item" item-count="20">
<reader ref="MyStepOneReader"/>
<processor ref="MyStepOneProcessor"/>
<writer ref="MyStepOneWriter"/>
</chunk>
</step>
<step id="stepTwo" next="stepThree">
<chunk checkpoint-policy="item" item-count="20">
<reader ref="MyStepTwoReader"/>
<processor ref="MyStepTwoProcessor"/>
<writer ref="MyStepTwoWriter"/>
</chunk>
</step>
<step id="stepThree">
<chunk checkpoint-policy="item" item-count="20">
<reader ref="MyStepThreeReader"/>
<processor ref="MyStepThreeProcessor"/>
<writer ref="MyStepThreeWriter"/>
</chunk>
</step>
</flow>
<flow id="stepOneOnlyFlow">
<step id="stepOne">
<chunk checkpoint-policy="item" item-count="20">
<reader ref="MyStepOneReader"/>
<processor ref="MyStepOneProcessor"/>
<writer ref="MyStepOneWriter"/>
</chunk>
</step>
</flow>
...
答案 1 :(得分:0)
repo = Repo.init(path).git
index = Repo(path).index
# add file to repo
repo.add(filename)
index.commit(message)
路径:存储库(.git)路径
文件名:您要添加哪个文件
消息:提交消息
在使用该方法作为休假之后;
repo = Repo(path)
commit = repo.head.commit
sha = commit.hexsha