Viewing an earlier version of a script

It looks like this may be a place to ask questions about using git as well as github. I’m sure this is a newbie question. I have learned how to use git to maintain versions of my script. I know how to revert to an earlier version of a script. What I seem to often want to do and am not sure how to do with git is to look at an earlier version without reverting to that version. I often want to remember how I did something, or figure out how I made a particular choice at some point in the script, sometimes to use part of an older version of my script in another project, while moving ahead with the current version of the script. How can I look at an earlier version of a script I am working on without reverting my whole project to that version?


1 Like

Hi and welcome to the forum!

The (relatively) simple way would be to use git checkout to set just that file to an older state:

git checkout old-ref -- your/file

Note that this overwrites the target file. :warning:

Or you could use git cat-file, which is a low level command, to output the content of a specific file at a specific ref (commit ID, branch, tag, …):

git cat-file -p old-ref:your/file

Finally you could use git worktree to check out the older ref in another directory, without duplicating the repository. :slightly_smiling_face:

1 Like

Thanks. Great response. --Kenoli

1 Like