LoginSignup
48
35

More than 5 years have passed since last update.

Gitでファイルの特定行の変更履歴を追う

Posted at

tl;dr

git log -L <start>,<end>:<file>

たとえば、Gemfileの1から10行目の変更履歴を表示したいとき

> git log -L 1,10:Gemfile

commit d9acf7548943f4c60be50ee43b54ce638d4d0d3a
Author: kmagai
Date:   Sun Apr 24 18:01:22 2016 +0900

    hoge


 -- a/Gemfile
 ++ b/Gemfile
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
@@ -1,6 +1,5 @@
 source 'https://rubygems.org'


 # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
 gem 'rails', '4.2.5.2'
 # Use sqlite3 as the database for Active Record

commit 3e858dafa6a9b0150e1607cc9befef4392d049dv
Author: kmagai
Date:   Sun Apr 24 12:14:21 2016 +0900

    init


 -- /dev/null
 ++ b/Gemfile
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
@@ -0,0 +1,6 @@
 source 'https://rubygems.org'


 # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
 gem 'rails', '4.2.5.2'
 # Use sqlite3 as the database for Active Record
48
35
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
48
35