2

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.

r5d
  • 579
  • 5
  • 24
Suzanne Soy
  • 3,027
  • 6
  • 38
  • 56
  • Does the 8.3 filename work? I think in this case it would be `BAZQUU~1`, but check using `dir /x`. – tom Sep 25 '13 at 10:35
  • 1
    `git mv` is really just `git rm` and `git add` (renames are not recorded as "rename" ops, they're dynamically recomputed) so if you can do the job with `add` and `rm`, that would suffice. I don't know how hard that would be on Windows; I avoid Windows as much as possible.... – torek Sep 25 '13 at 10:57
  • @tom I don't think that would change anything: I *can't* checkout the file, so I need to move it even if the file doesn't exists. – Suzanne Soy Sep 25 '13 at 13:28
  • @torek Thanks for the heads-up, I found a solution using `git show old-name > new-name` to checkout the old file with a new name, and `git add new-name` followed by `git rm --cached old-name`. That doesn't work well for badly named directories though. – Suzanne Soy Sep 25 '13 at 13:36
  • 1
    @GeorgesDupéron Sorry, I misread the question. Regarding renaming directories, I think this can be done using a combination of [ls-tree](https://www.kernel.org/pub/software/scm/git/docs/git-ls-tree.html), [mktree](https://www.kernel.org/pub/software/scm/git/docs/git-mktree.html) and possibly also [replace](https://www.kernel.org/pub/software/scm/git/docs/git-replace.html). See [Raw Git](http://www.alexgirard.com/git-book/7_raw_git.html) for an introduction. – tom Sep 26 '13 at 10:48

1 Answers1

2

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).

Boris Brodski
  • 8,425
  • 4
  • 40
  • 55
Suzanne Soy
  • 3,027
  • 6
  • 38
  • 56