Reputation: 9114
I'm facing issue while checking out a branch in windows. One folder ends with an empty space in it, causing windows to automatically trim the folder, while git is trying to put files in original path and causing an error.
fatal: cannot create directory at 'raisesoft/61571_delivery /acl': No such file or directory
On linux it works fine as linux doesn't trim the folders automatically.
I'm trying to rename that folder. This is the script I came up with:
git filter-branch --tree-filter '
if [ -d "61571_delivery " ]; then
mv "61571_delivery " "61571_delivery"
fi' --force HEAD
However it doesn't work. It didn't rename the folder at all. I'm not proficient in linux bash, so little help would be greatly appreciated.
Thanks
Upvotes: 1
Views: 669
Reputation: 488193
You are basically on the right track. Your tree filter is just looking for the wrong name. The path name of the directory is not:
"61571_delivery "
(complete with trailing space that needs a quote mark to make it clear), but rather:
"raisesoft/61571_delivery "
Hence:
git filter-branch --tree-filter '
if [ -d "61571_delivery " ]; then
mv "61571_delivery " "61571_delivery"
fi' --force HEAD
should read:
git filter-branch --tree-filter '
if [ -d "raisesoft/61571_delivery " ]; then
mv "raisesoft/61571_delivery " "raisesoft/61571_delivery"
fi' --force HEAD
(and once you test it and see that it works, switch to --all
and add --tag-name-filter cat
to get annotated tags changed as well).
It's worth noting that --tree-filter
is extremely slow. On a large repository, doing this on spinning media (rather than SSD or memory file system) can take days or even weeks. You can speed it up a lot by using a memory file system, but your biggest speedup comes from using an --index-filter
rather than a --tree-filter
. With a tree filter, Git must extract each commit from the index into a regular file system tree, run your filter, then convert the tree back into an index it can use to write a new commit. While no part of git filter-branch
is fast, this is the slowest part. With an index filter, Git gets to skip this step entirely: it just reads the commit into the index, runs your index filter, then writes a new commit from the index.
Unfortunately, there's no good out-of-the-box way to write an index filter that does this. You basically want the Git equivalent of hg mv --after
to rename files in the index only—but Git doesn't have it. I wrote a script that does this for one file, but you want to do it for every file within a directory.
Upvotes: 1