haiju's 開発メモ

開発に必要な情報を自分用にメモ

gitでリポジトリから不要になったファイルを削除する

テストと本番サーバーのPHPのバージョンが古すぎてローカル開発

環境に構築できないので、ローカルで開発したコードをテストサー

バーにわざわざgit渡しで動作確認とデバッグを行っているが、

その際に検証用のためだけに作成したファイルがあり、共有のため

リモートブランチに登録してしまって気持ち悪いことになるので、

作業が終わったらリモートサーバーから削除したい。

というのを調べてみた。

調べたけど実行は終わってからw(ΦωΦ)

[手順]

1.リポジトリから削除、かつ、ディレクトリから削除

$ git rm FILENAME

※ちなみに以前の以下の作業と同じ

$ rm FILENAME

$ git add FILENAME

※rmでファイル削除して、$ git add FILENAMEを実行すると

 今では以下のwarningメッセージが出るので、同じ意味だよー

 ということで受け止めておくだけにするw(ΦωΦ;)

warning: You ran 'git add' with neither '-A (--all)' or '--ignore-removal',
whose behaviour will change in Git 2.0 with respect to paths you removed.
Paths like 'geppou_dup_del2.php' that are
removed from your working tree are ignored with this version of Git.

* 'git add --ignore-removal <pathspec>', which is the current default,
ignores paths you removed from your working tree.

* 'git add --all <pathspec>' will let you also record the removals.

Run 'git status' to check the paths you removed from your working tree.

2.リポジトリから削除、ローカルには残す

$ git rm --cached FILENAME

3.リポジトリから履歴ごと削除

 こちらは、あとで詳しく読んで必要があればやる。

4.あとは、とりあえずコミットする。

※違ったら詳しく読んで対応する

[参考サイト]

techacademy.jp

yatta47.hateblo.jp

mimaunes.hatenablog.com

qiita.com

qiita.com

d.hatena.ne.jp

qiita.com

qiita.com