accessing file content for specific commit sha

Viewed 12

I have two types of files (xml and java) I tried to access a specific file to a specific commit SHA , and after that, I want to print the content of this file from line X to line Z For example, I have this ** java file path:**

"\Users\mine\Desktop\studied\projects\2012-code\2012Robot\src\edu\wpi\first\wpilibj\templates\OI.java"

and the SHA commit : 7680ba96304317a2c52ae3a96cb83019698a07a9

and I want to print only lines from 52 to 54 in that file

my code was :

    repo = Repo(r'C:\Users\mine\Desktop\studied\projects\2012-code')

    commit =repo.commit('7680ba96304317a2c52ae3a96cb83019698a07a9')
    targetfile = commit.tree / 'OI.java'
    data = targetfile.data_stream.read()

it did not work and I have this error : KeyError: "Blob or Tree named 'OI.java' not found" however, I am sure that file is on my local machine. also, I tried to put the file path and it did not work

Any thought?

0 Answers
Related