LoginSignup
6
6

More than 5 years have passed since last update.

Gitの差分ファイル抽出時にスペースを含んだファイル名でエラー

Posted at

gitで差分ファイルを抽出する

こちらの記事を参考にして差分ファイル抽出していたところ、エラー発生。
archive.zipは空ファイルになってしまって抽出できておらず。

$ git archive --format=zip --prefix=root/ HEAD `git diff --name-only d0b642e 17945a1` -o archive.zip
fatal: path not found: tokyo.html

tokyo.htmlなんてないんだが...
と思ったのですが、よく見るとファイル名にスペースが含まれているではないですか!

$ git diff --name-only d0b642e 17945a1 | grep tokyo
aaa/bbb/ccc_ tokyo.html

仕方ないので、ファイル名にスペースを含むファイルを除外して抽出しました。

$ git archive --format=zip --prefix=root/ HEAD `git diff --name-only d0b642e 17945a1 | sed '/ /d'` -o archive.zip

ちなみにダブルクォーテーションで囲む方法も試したのですが、ダメでした。

$ git archive --format=zip --prefix=root/ HEAD `git diff --name-only d0b642e 17945a1 | sed 's/\(^.*$\)/"\1"/g'` -o archive.zip
fatal: path not found: "404/index.html"
6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6