TechBlog masa

  • Top
  • Posts
  • Profile
2025-02-23
SWE
🍎Macで“index.tsx 2”的なファイルが時々増える人向け: 開発ディレクトリをお引越ししてiCloudから外す, その後のgit対応
Macshell

likes: 0

Unsupported Block: table_of_contents

 

rsyncコマンドで、元ディレクトリからコピーする。

以下に注意しないと、昔に削除したディレクトリもコピーされた。

X rsync -av ./Desktop/forCursor ./

O rsync -av ./Desktop/forCursor/ ./forCursor/

Xは、./Desktop/forCursorディレクトリをカレントディレクトリにコピーする。Oは、./Desktop/forCursor内のディレクトリとファイルを./forCursor内にコピーする。

# .gitも除外する。必要なものはリモートに存在しているから。
# 何か問題があったらそのディレクトリのみ個別に.git/付きでrsyncすれば良い。
rsync -av \
--exclude "node_modules/" \
--exclude "build/" \
--exclude "dist/" \
--exclude "out/" \
--exclude "lib/" \
--exclude "__pycache__/" \
--exclude ".git/" \
./Desktop/devdir/ .devdir/

.gitは無視しているので、gitでの開発を再開するには以下を行う

fetchした後は、ローカル内がすべて未追跡ファイルになっている。これをリモートの main の状態に強制的に合わせるために、reset, cleanを行う。

!!!デフォルトブランチがmainじゃない場合は指定に注意. devになってるかも!!!

git init
git remote add origin <ssh-url>
git fetch --all

git reset --hard origin/main
git clean -fd
git switch main

 

 

iCloudが原因。

iCloudは同期に失敗するとコピーを作る。そのコピーされたものが”index.tsx 2”など。

Unsupported Block: heading_2

iCloudのディレクトリ以外に開発ディレクトリを置く。

自分の場合はデスクトップ直下に入れていたが、以下の通りデスクトップはiCloudのデスクトップにシンボリックリンクが貼られている(Library/Modibe …がiCloudのディレクトリ)。

/Users/miwa/Library/Mobile Documents/com~apple~CloudDocs

lrwxr-xr-x@  ...  Desktop -> /Users/miwa/Desktop

よって、iCloudディレクトリからシンボリックシンクが貼られていないローカルディレクトリに開発ディレクトリを置けば良さそう。

シンボリックリンクが貼られているのはDesktop, Documentsのみだった。

Unsupported Block: heading_2

/Users/{username}/に開発ディレクトリを丸々写した。

純粋にmv ~/Desktop/{devDir} ~/で実行…したかったのだが何故か全く動かない。-vオプションでログを出力させようとしても一切音沙汰なし、終わることもない。以下によればmvのプロセスは実行中になっているようだが、全く音沙汰なし。

[miwa]~ ps aux | grep mv
miwa             56711   0.0  0.0 410733264   1504 s067  S+   12:27AM   0:00.00 grep mv
miwa             56688   0.0  0.0 410592928   1120 s063  S+   12:26AM   0:00.00 mv -v ./Desktop/forCursor/achieeeve ./forCursor

しょうがなくcpで実行しようとしたが、cpには-vオプションがない。ちょっと嫌なので代替案を探す。

cpより便利なrsyncを使う。

# .gitも除外する。必要なものはリモートに存在しているから。
# 何か問題があったらそのディレクトリのみ個別に.git/付きでrsyncすれば良い。
rsync -av \
--exclude "node_modules/" \
--exclude "build/" \
--exclude "dist/" \
--exclude "out/" \
--exclude "lib/" \
--exclude "__pycache__/" \
--exclude ".git/" \
./Desktop/devdir/ ./devdir/

以下のXだと、昔に削除したディレクトリもコピーされたので注意。

X rsync -av ./Desktop/forCursor ./

O rsync -av ./Desktop/forCursor/ ./forCursor/

Xは、./Desktop/forCursorディレクトリをカレントディレクトリにコピーする。Oは、./Desktop/forCursor内のディレクトリとファイルを./forCursor内にコピーする。

 

Unsupported Block: heading_2
  • 各プロジェクトでリモートのデータをローカルに反映してから作業再開。.gitは無視しているので、gitでの開発を再開するには以下を行う。
    git init
    git remote add origin <ssh-url>
    git fetch --all
    
    git reset --hard origin/main
    git clean -fd
    git switch <branch-name>

    fetchした後は、ローカル内がすべて未追跡ファイルになっている。これをリモートの main の状態に強制的に合わせるために、reset, cleanを行う。

  • もしあれば、開発ディレクトリへの移動用エイリアスのパスを修正。
  • vscode関係の”code”をインストールする必要はなかった。

 

https://qiita.com/thinkalot/items/246ec53804d907950e23

https://zenn.dev/maztak/articles/03715960434485

https://qiita.com/KEINOS/items/a74f20e58011aa6cdee4

https://qiita.com/C_HERO/items/6fe4f650d785815a7597

https://qiita.com/sogawa-BitStar/items/3e8df09328467814715f

 

breadcrumb予定地
profileCard予定地

SideBarPage

共有ボタン予定地
他ボタン予定地