Created
November 5, 2015 22:16
-
-
Save mattboehm/5f6b5d8a00be43601c39 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
if [ "$#" -ne 2 ] | |
then | |
echo "move a directory to a new location. | |
While normally, git mv old-dir new-dir should work, let's say you do that and then try to merge in another branch where someone's added new files to old-dir. | |
these files will stay in old-dir, and we need a way to merge their (arbitrarily deeply nested) contents into new-dir. This script uses cp -r to merge the contents, | |
followed by git add/rm. When you do git status, it should now show that all those files have been moved. | |
Warning: script will add the whole target directory, including uncommitted changes on files that existed before it ran." | |
echo "usage: $0 <old-dir> <new-dir>" | |
exit 0 | |
fi | |
if [ -e $1 ] | |
then | |
#make the target directory if it doesn't exist | |
mkdir -p $2 | |
#copy all the contents into that directory | |
cp -r "$1"/* $2 | |
git rm -r "$1" | |
git add "$2" | |
else | |
echo "Error! source directory does not exist" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment