フォルダ構成を変えると追跡できなくなる

ファイルを追跡したまま移動するには・・・?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
PS > git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
deleted: Dockerfile
deleted: app.py
deleted: docker-compose.yml
deleted: requirements.txt

Untracked files:
(use "git add <file>..." to include in what will be committed)
webapp/

追跡を維持したまま移動するにはgit mvを使う?

git mvを使えばrenamedと認識されるが、ワイルドカードは使えないしめんどくさい。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
PS > git mv app.py webapp
PS > git mv docker-compose.yml webapp
PS > git mv Dockerfile webapp
PS > git mv requirements.txt webapp
PS > git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
(use "git restore --staged <file>..." to unstage)
renamed: Dockerfile -> webapp/Dockerfile
renamed: app.py -> webapp/app.py
renamed: docker-compose.yml -> webapp/docker-compose.yml
renamed: requirements.txt -> webapp/requirements.txt

いやいや、ファイル名やフォルダ構成を変えるだけでgit mvは必要ない

gitはファイルの内容で判断するので、-Aオプションを実行するこでrenamedになる。
-Aを付けることで、全ての変更がaddされる。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
PS > git add . -A
warning: CRLF will be replaced by LF in webapp/Dockerfile.
The file will have its original line endings in your working directory
warning: CRLF will be replaced by LF in webapp/app.py.
The file will have its original line endings in your working directory
warning: CRLF will be replaced by LF in webapp/docker-compose.yml.
The file will have its original line endings in your working directory
warning: CRLF will be replaced by LF in webapp/requirements.txt.
The file will have its original line endings in your working directory
PS > git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
(use "git restore --staged <file>..." to unstage)
renamed: Dockerfile -> webapp/Dockerfile
renamed: app.py -> webapp/app.py
renamed: docker-compose.yml -> webapp/docker-compose.yml
renamed: requirements.txt -> webapp/requirements.txt