Search code examples
pythonwindowsgitpython

How to save the results of git show as an excel file


I want to save a certain version of the excel file using python

I have used git show to get the content of this excel

git show 17ed4f74:xxx.xlsx

output: enter image description here

how to save it as an .xlsx file


Solution

  • output = repo.git.execute(["git", "show", flag + ":" + git_path], None, False, True, False, None, False)
    with open(remote_file_path, 'wb') as f:
        f.write(output)
    

    git.execute the seventh parameter:

    stdout_as_string – if False, the commands standard output will be bytes. Otherwise, it will be decoded into a string using the default encoding (usually utf-8). The latter can fail, if the output contains binary data.