Last active
September 2, 2019 17:12
-
-
Save JoshData/0d64ec5451bde475b41980d577d23c85 to your computer and use it in GitHub Desktop.
Discard changes in git working directory that are only changes in case
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
# This bash script can be used to drop changes in your git working directory that are only changes | |
# in upper/lowercase. This is useful if you are working on a case-insensitive document, such | |
# as a Visual Basic 6 source code file (ugh), and your tools accidentally change the case of | |
# words, but you want to revert that before making a commit. After this script finishes, your | |
# working directory has your changes except for those that were only changes in case. | |
# | |
# This script takes the following actions: | |
# | |
# 1) Use "git difftool" with "diff -i" to run a case-insensitive diff on the | |
# working directory and save that to a temporary patch file case_insensitive_changes.patch. | |
# 2) Use 'git stash' to discard all the changes in a safe way in the current directory and its subdirectories. | |
# 3) Apply the patch file, which has the case-insensitive changes only. | |
# 4) If that succeeded, drop the stash and delete the patch. (Your case changes are now gone forever.) | |
# 5) Otherwise, if it failed, restore what was discarded using "stash pop." | |
git difftool -yx "diff -iu" > case_insensitive_changes.patch \ | |
&& git stash push . \ | |
&& git apply -v -p0 - < case_insensitive_changes.patch \ | |
&& rm case_insensitive_changes.patch \ | |
&& git stash drop \ | |
|| git stash pop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment