LoginSignup
3
2

More than 5 years have passed since last update.

git filter-branch でディレクトリを移動する

Posted at

動作確認のために次のようにリポジトリを作ります。

$ mkdir aaa
$ touch aaa/.htaccess
$ touch aaa/"空 白"
$ touch aaa/$'改\n行'
$ touch aaa/$'寿司\xF0\x9F\x8D\xA3 \xF0\x9F\x8D\xA3\n\xF0\x9F\x8D\xA3'
$ git init
$ git add .
$ git commit -m first
$ git ls-files
aaa/.htaccess
"aaa/寿司? ?\n?"
"aaa/改\n行"
aaa/空 白

git filter-branch で aaa ディレクトリを bbb に変更します。

$ git filter-branch -f --tree-filter '
  [ ! -d aaa ] || {
    [ -d bbb ] || mkdir bbb;
    find aaa -mindepth 1 -print0 | xargs -0 -i mv -v {} bbb;
  }
' HEAD

移動出来ました。

$ git ls-files
bbb/.htaccess
"bbb/寿司寿司寿司? ?\n?"
"bbb/改\n行"
bbb/空 白
3
2
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
3
2