Skip to content

Instantly share code, notes, and snippets.

@JadedEvan
Last active October 21, 2016 15:04
Show Gist options
  • Save JadedEvan/a033e9883e77334bec5106e380406b96 to your computer and use it in GitHub Desktop.
Save JadedEvan/a033e9883e77334bec5106e380406b96 to your computer and use it in GitHub Desktop.
How to revert a file to a known working state and apply upstream changes in a patch from a different branch.
# Check out the original file should receive the changes. This should be the version on your working branch
git checkout {MY-WORKING-BRANCH-SHA} -- path/to/my/file.txt
# Generate a diff of the file, ignoring space changes against a known branch. You should be on your working branch for this
git checkout my-working-branch
git diff HEAD..master --ignore-space-change -- path/to/my/file.txt > patch.diff
# Apply the patch. Note that you MUST use the same --ignore-space-change flag to apply properly
git apply --ignore-space-change patch.diff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment