I use a patch file. This way I can edit the paths in the patch file to match the new location(s).
You can create a patch file with:
git format-patch {commit}~1...{commit}
This generates a .patch
file in the local directory with the changes.
-or-
git show {commit} > {my-changes.patch}
Where {my-changes.patch}
is a filename/path you determine.
Now edit the {my-changes.patch}
file in an editor and replace old paths with new paths. Other edits or changes can be made at this time.
Now you can apply the patch with:
git am < {my-changes.patch}
If you edited something and broke the patch, you will get an error. Check the steps and edits you may and try again. One nice thing about this method is that you can just reset, undo portions of an edit, or entire files in the edit if you like. But, the changes being applies are free of user typos, since git is doing the merge from the original changes.
It is important that before you commit the changes, diff the changes you have made and make sure they are what you want. Only then stage and commit them.
Note: git am
has a bunch of options, like --ignore-whitespace
and --interactive
that can help you.