I'm new here so I apologize if this isn't the place to ask this question. I'm writing a python script for my company that looks through files in certain commits and compares them. Well I'm not familiar with git and how commits work so maybe someone more knowledgeable than me can help. What I have so far is something along the lines of this:
import git
# Directory for my repo
repo = git.Repo(<repo path>)
# Get the current commit and save it for later use
commit = repo.commit()
< Here is where I search through the current files to get my info >
# Checkout the old commit
repo.git.checkout("HEAD~1", force=True)
< Here is where I search through the old files to get my info >
# Re-checkout the current commit
repo.git.checkout(commit.hexsha, force=True)
< Now I want to be back where I started >
This works well and it almost accomplishes what I want it to. However... the whole reason for this script is to check changes to files. In other words, the developer will work on and change many of the files so that they are different from the last commit. The problem is when this checks out the newer commit again, the changes are gone (obviously very frustrating to the developer). So the process overall is something is like this:
--> new_commit on local machine (with changes from developer)
--> old_commit checked out to see what changed
--> new_commit checked back out (as if the developer never worked on it)
Overall, my question is: is there any way that I can save this new commit with the changes so that when re-checked out it still has the changes? Thank you for any help!
Edit: What I want to achieve is storing the uncommitted/unstaged changes to the version currently checked out, then checkout and older version, and finally bring back the uncommitted/unstaged changes.