1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Gitでファイルの変更履歴を確認する方法まとめ

Posted at

はじめに

不具合の修正をしていて、あれ?直っているけど、いつ直ったんだろうとか思った時に調べたいことがあると思います。
その時に使える方法をまとめたいと思います。

ファイルのコミット履歴を確認する

ファイルのパスは指定は、VS Codeの場合、対象のファイルを右クリックして、相対パスのコピーを行い、ペーストすると楽です。

コミット履歴だけ確認

git log src/sample.js

履歴が長い場合、Enterを押すと次の行が表示されます。qを入力してEnterを押すと終了します。(他のコマンドも同様です)

コミット履歴と内容を確認

git log -p src/sample.js

編集した人を指定する

git log --author user -p src/sample.js

ファイルの行ごとの変更履歴を確認する

git blameというコマンドで行ごとの変更履歴が確認できます。
ここらへんの行の変更が不具合の原因っぽいなーって時に、行数指定で絞り込み、使うことが多いです。

ファイル全行

git blame src/sample.js

行数指定

git blame -L 4,6 src/sample.js

コミットからどのPRを確認する

対象のコミットが確認できたら、コミットハッシュ値を確認します。
commit 1123x912x300a0490c84ed58k2123307d0ae0feaという部分です。

GUIだとPull requestsのフィルターにペーストして検索すれば、そのコミットを含んだPRがわかります。

image.png

CUIを使いたい場合は、以下の方法で確認できそうです。

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?