0

Let's say I have a Python script called example.py which I've committed to git several times. Now what I want is to have a different script called run_example.py which relies on the first script and takes as a command-line (or configurable) argument the commit SHA hash of example.py it should use, e.g.

python run_example.py <desired SHA of example.py>

and thus by specifying a different commit hash, a different version of example.py would be referenced and run.

What's the cleanest way to achieve this?

1
  • You'd need to call a subprocess to check out a version of the file, or have a native python interface to git. Either way, you are likely looking for a third party tool. Commented Jul 18, 2019 at 19:29

1 Answer 1

1

One option: make a temporary version of your script at the desired revision, then delete it when finished:

$ git show <desired SHA>:example.py > tmp-example.py
$ python run_example.py tmp-example.py
$ rm tmp-example.py
Sign up to request clarification or add additional context in comments.

2 Comments

I wrote a demo and tried git show <desired SHA>:example.py | python, and it worked. But not sure if it's okay for all cases.
Cool! I guess that could be a little risky in some cases. If it works for you, let me know and I’ll update the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.