Created
June 14, 2012 06:24
-
-
Save bcbnz/2928322 to your computer and use it in GitHub Desktop.
Removing change of a folder in Git
This file contains 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
Upgraded a dependency in a Git repository to an incompatible version but due to insufficient testing didn't notice until several commits later. I *could* have just done a simple revert but was bored and figured out how to wipe it from history completely (usual disclaimer, rewriting history in a repository you have shared with anybody else is not a nice idea). | |
To fix it: | |
* Put a copy of the original folder (i.e., the one you actually want) in a separate location. | |
* Run the command in the script file below. This runs through each commit (so it could be very slow for a large repo), and checks if the new folder is present. If so, it deletes it and copies in the original. The tree-filter takes care of the Git add & rm commands as needed. The --prune-empty argument tells it to get rid of any empty commits (i.e., the one you committed the change in). |
This file contains 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
git filter-branch --prune-empty --tree-filter ' | |
if [ -d newfolder ]; | |
then | |
rm -rf newfolder; cp -r /tmp/oldfolder . | |
fi' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment