Question

I have a git repository containing a file which has an invalid name under windows:

foo/bar/baz|quux

Since I wanted to fix the problem without rebooting, I tried the following commands:

git clone -n ssh://example.com/home/me/repo.git
git mv "foo/bar/baz|quux" "foo/bar/baz-quux"

But all I get is:

fatal: bad source, source=foo/bar/baz|quux, destination=foo/bar/baz-quux

I ended up running that command under linux, with a checked-out repo (git clone without -n), and id worked like a charm, so I guess the fatal error is due to the fact that the file isn't checked-out under windows (since I can't check it out).

So how would I run git mv --index "foo/bar/baz|quux" "foo/bar/baz-quux" so it only modifies the index, but ignores the fact that the file is not on the disk? The option --index isn't available for git mv, and I tried -f but it failed with the same message.

Was it helpful?

Solution

I found a solution:

git clone -n ssh://example.com/home/me/repo.git

# Create foo/bar since the checkout -n didn't create it
mkdir -p foo/bar/

# Create the new file
git show "foo/bar/baz|quux" > "foo/bar/baz-quux"
git add "foo/bar/baz-quux"

# Remove the old file in the index
git rm --cached "foo/bar/baz|quux"

git commit -m "Moved file with invalid name."

Note this doesn't allow to easily move a directory with an invalid name -- you'd have to git show origninal-name > new-name each file (although a small shell script could help if there were many files).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top