DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Trace File Change History in Git Repository


The website need hide some menu items under developing, by comment out the html codes (at line 19~24 in file "client/comTemp.html"). But last night we found they reappeared in the newest version. Apparently someone used the older version (in which they were not commented out) overwrite the latest version by error (without intention).

How to find out who, at which commit make this mistake?

Step 1: get the error version.

$ git blame -L 19,24 client/comTemp.html
dc7d385a (Tom     2015-06-26 17:39:28 +0800 19)    <li>
8b64184a (Bob     2015-05-04 19:32:43 +0800 20)      <a href="/mall">Mall</a>
6bb3ba70 (Franky  2015-05-04 15:45:50 +0800 21)    </li>
6bb3ba70 (Franky  2015-05-04 15:45:50 +0800 22)    <li>
8b64184a (Bob     2015-05-04 19:32:43 +0800 23)      <a href="/services">Services</a>
dc7d385a (Tom     2015-06-26 17:39:28 +0800 24)    </li>

Here the line 19 should be <!--<li> and line 24 should be </li>-->, to hide "Mall" and "Services", which are under developing.

Step 2: get the newest right version.

The wrong commit is "dc7d385a", so we have to find the nearest change before it:

$ git blame -L 19,24 'dc7d385a^' -- client/comTemp.html
96269db1 (Bob     2015-06-10 15:36:31 +0800 19)    <!--<li>
8b64184a (Bob     2015-05-04 19:32:43 +0800 20)      <a href="/mall">Mall</a>
6bb3ba70 (Franky  2015-05-04 15:45:50 +0800 21)    </li>
6bb3ba70 (Franky  2015-05-04 15:45:50 +0800 22)    <li>
8b64184a (Bob     2015-05-04 19:32:43 +0800 23)      <a href="/services">Services</a>
96269db1 (Bob     2015-06-10 15:36:31 +0800 24)    </li>-->

So we know Mall and Services were commented out at commit 96269db1, 2015-06-10, and uncommented by error at commit dc7d385a, 2015-06-26, by Tom.

Step 3: show code changes.

$ git show dc7d385a -- client/comTemp.htm
...
-    <!--<li>
+    <li>
       <a href="/mall">Mall</a>
     </li>
     <li>
       <a href="/services">Services</a>
-    </li>-->
+    </li>
...

It shows in commit dc7d385a, two lines were deleted: "", while two lines were added: "

  • " and "
  • ".

    Step 4 (optional): revert the commit

    git revert dc7d385a
    

    Ref: http://stackoverflow.com/questions/14836696/delete-last-commit-in-bitbucket



    Published

    Jun 30, 2015

    Last Updated

    Jun 30, 2015

    Category

    Tech

    Tags

    • blame 1
    • git 36
    • show 1

    Contact

    • Powered by Pelican. Theme: Elegant by Talha Mansoor