0

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?

waled
  • 3
  • 2
  • 1
    What happens if you attempt to access the file using the `git` command line? If you `git ls-tree 7680ba96304317a2c52ae3a96cb83019698a07a9^{tree}`, what is the output? Given what you've shown us, I wouldn't expect the file `OI.java` to be part of the commit tree; it looks like it is several directories further down. E.g., `commit.ree / "2012Robot/src/edu/wpi/first/wpilibj/templates/OI.java"`. – larsks Sep 22 '22 at 02:47

0 Answers0