20
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Git】削除したファイルだけaddする方法

Last updated at Posted at 2019-06-22

GitHubに削除したファイルの変更分だけをaddして、pushしたい場合があったのでメモ。対象: rmコマンドや右クリックなんかでファイルを削除 => その他のファイルを編集したが、削除済のファイルの変更分のみGitHubにあげたい。

結論

削除したファイルの変更分だけをadd

$ git rm $(git ls-files --deleted)

実行結果

git rm $(git ls-files --deleted) 実行後
対象ファイル(削除したファイル)のディレクトリが出力される

$ git rm $(git ls-files --deleted)
rm 'app/views/labels/_form.html.erb'
rm 'app/views/labels/_label.json.jbuilder'
rm 'app/views/labels/edit.html.erb'
rm 'app/views/labels/index.html.erb'
rm 'app/views/labels/index.json.jbuilder'
rm 'app/views/labels/new.html.erb'
rm 'app/views/labels/show.html.erb'
rm 'app/views/labels/show.json.jbuilder'

git status で、ちゃんとaddされてGitのステージングエリアに上がっているか確認

$ git status
On branch label
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

	deleted:    app/views/labels/_form.html.erb
	deleted:    app/views/labels/_label.json.jbuilder
	deleted:    app/views/labels/edit.html.erb
	deleted:    app/views/labels/index.html.erb
	deleted:    app/views/labels/index.json.jbuilder
	deleted:    app/views/labels/new.html.erb
	deleted:    app/views/labels/show.html.erb
	deleted:    app/views/labels/show.json.jbuilder

Changes to be committed: 

ちゃんとGitのステージングエリアに上がってることが確認できた

以上

https://qiita.com/hkato193/items/0097620bdf4c6eeef308
https://rfs.jp/server/git/gite-lab/git-ls-files.html
http://chroma.hatenablog.com/entry/2013/10/18/111052

20
9
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
20
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?