Last active
March 13, 2020 10:43
-
-
Save hartikainen/2cd351aea6af11b1a48632bc51aa9985 to your computer and use it in GitHub Desktop.
Saves the diff between index and working copy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# NOTE(hartikainen): Might want to check that the working tree is clean. | |
commit_sha="$(cat ./name_rev.txt | awk -F' ' '{print $1}')" | |
git checkout "${commit_sha}" | |
echo "Applying patch: $(cat ./patch.diff)" | |
git apply patch.diff |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import git | |
repository_path = os.getcwd() | |
repository = git.Repo(repository_path, search_parent_directories=True) | |
# See https://gitpython.readthedocs.io/en/stable/tutorial.html#obtaining-diff-information | |
diff = repository.git.diff('HEAD') | |
with open('./patch.diff', 'w') as f: | |
# NOTE(hartikainen): Needs a line break at the end in order for | |
# `git apply ...` to work. | |
f.write(f"{diff}\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment