3

I have a git repo of my music files, and I have recently detected that some are deleted. I suppose I accidentally deleted them, however now I have only too-briefly reveled in the fact that I had the foresight to use a git repo, so my current git status verifies they have been deleted. Here is the listing of a few:

# deleted:  Steve_Erquiaga-Cafe_Paradiso/03 - Arioso__J.S._Bach_.flac
# deleted: "Steve_Erquiaga-Cafe_Paradiso/04 - S\303\203\302\251r\303\203\302\251nade__Rachmaninov__from_Moreaux_de_fantasie.flac"
# deleted: "Steve_Erquiaga-Cafe_Paradiso/05 - After_a_Dream__Faure___Apr\303\203\302\250s_Une_R\303\203\302\252ve_.flac"
# deleted:  Steve_Erquiaga-Cafe_Paradiso/06 - Prelude_in_C_Minor__J.S._Bach__from_The_Well-Tempered_Clavier.flac
# deleted:  Steve_Erquiaga-Cafe_Paradiso/07 - If_Dreams_Could_Dance__Erquiaga_.flac

I have already restored one song that did not contain special characters in its name by using:

$git checkout "copy/pasted-in_name_from the output above"

However the special characters in some of the names are blocking my simplistic approach to restore them:

$git checkout 'Steve_Erquiaga-Cafe_Paradiso/05 - After_a_Dream__Faure___Apr\303\203\302\250s_Une_R\303\203\302\252ve_.flac'

Error:

pathspec 'Steve_Erquiaga-Cafe_Paradiso/05 - After_a_Dream_Faure__Apr\303\203\302\250s_Une_R\303\203\302\252ve_.flac' did not match any file(s) known to git.

I suppose it is not a git issue per se, rather a shell special-character escaping or translating issue. I tried putting the name in double quotes, as it is displayed, but I got the same message. I also tried it with outer double-quotes and preceding each 'inner double quote' with a backslash, garnering the same type of error message.

How can I construct a git checkout command that will work using these file names?

Zoe
  • 27,060
  • 21
  • 118
  • 148
user60985
  • 61
  • 1
  • 5
  • If you're happy with checking out all files and not specifically named ones, `git checkout .` – laalto Nov 16 '11 at 12:47

2 Answers2

2

You can try using printf, which understands 3-character octal escapes, e.g.:

git checkout -- "$(printf "Steve_Erquiaga-Cafe_Paradiso/05 - After_a_Dream__Faure___Apr\303\203\302\250s_Une_R\303\203\302\252ve_.flac")"

I haven't tested this, I'm afraid, but I think it should work.

Mark Longair
  • 446,582
  • 72
  • 411
  • 327
0

Try using double quotes instead of single quotes in your git checkout command. Escape sequences generally work inside double-quoted strings but not single quoted.

And here's an even easier idea, but it could erase local changes:

git checkout .
David Grayson
  • 84,103
  • 24
  • 152
  • 189
  • 1
    it may be useful to explain what the command does? it's not obvious – CharlesB Nov 16 '11 at 17:39
  • 1
    I think `git checkout .` basically reverts all your changes in the current directory (.) to be the same as the "index" (the stuff you have added with `git add` or `git rm`). Instead of doing `git checkout filename` to revert a file, you can do `git checkout .` to revert a whole directory. – David Grayson Nov 16 '11 at 20:02