iT邦幫忙

2017 iT 邦幫忙鐵人賽
DAY 23
0
自我挑戰組

Git學習筆記系列 第 23

git blame 幫你找出程式碼內的那一行是誰最後動的

  • 分享至 

  • twitterImage
  •  

今天介紹的指令是git blame

他是一個可以用來查看指定的檔案內每一行是由誰最後異動的指令

$ git blame index.html
^dc1942c (Tom       2016-12-22 21:09:40 +0800  1) <!DOCTYPE html>
^dc1942c (Tom       2016-12-22 21:09:40 +0800  2) <html>
^dc1942c (Tom       2016-12-22 21:09:40 +0800  3) <head>
fe2f39dc (momo      2016-12-25 12:58:49 +0800  4)     <meta charset="utf-8">
fe2f39dc (momo      2016-12-25 12:58:49 +0800  5)     <meta name="viewport" content="width=device-width">
fe2f39dc (momo      2016-12-25 12:58:49 +0800  6)     <title>My Page</title>
^dc1942c (Tom       2016-12-22 21:09:40 +0800  7) </head>
^dc1942c (Tom       2016-12-22 21:09:40 +0800  8) <body>
fe2f39dc (momo      2016-12-25 12:58:49 +0800  9)     <h1>momo's page lala edit</h1>
fe2f39dc (momo      2016-12-25 12:58:49 +0800 10)     <div>learning git</div>
fe2f39dc (momo      2016-12-25 12:58:49 +0800 11)     <div>change remote url</div>
1493b189 (momo      2016-12-26 23:05:03 +0800 12)     <div>prepare</div>
49f5c491 (momo      2016-12-26 23:05:52 +0800 13)     <div>use the rebase</div>
850ed168 (momo      2016-12-26 23:16:06 +0800 14)     <div>deBug deBug deBug</div>
^dc1942c (Tom       2016-12-22 21:09:40 +0800 15) </body>
1bd2f366 (momo      2016-12-28 15:59:18 +0800 16) </html>

我們也可以只顯示特定行號

​$ git blame -L 5,8 index.html 

fe2f39dc (momo      2016-12-25 12:58:49 +0800 5)     <meta name="viewport" content="width=device-width">
fe2f39dc (momo      2016-12-25 12:58:49 +0800 6)     <title>My Page</title>
^dc1942c (Tom       2016-12-22 21:09:40 +0800 7) </head>
^dc1942c (Tom       2016-12-22 21:09:40 +0800 8) <body>

特別注意:git blame只看得到還在的程式的最後異動人,若是一行已經被刪掉的程式,就查看不到了

git-blame 官方文件


上一篇
合併多個commit為1個
下一篇
互動式協助找出有問題的commit:git-bisect
系列文
Git學習筆記31
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言