How to find out in which commit a particular code was added?

前端 未结 5 706
执念已碎
执念已碎 2020-12-22 22:13

I want to find out in which commit did I add the code given below:

if (getListView().getChildCount() == 0)
                getActivity().findViewById(androi         


        
5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-22 23:12

    Run git blame on the file. It'll show you the commit ID, the date and time, and who committed it- for each line. Then just copy out the commit identifier and you can use it in git log or git show .

    For example, I've got a file, called test.txt, with lines added on different commits:

    $ cat test.txt
    First line.
    Second line.
    

    Running the git blame:

    $ git blame test.txt
    ^410c3dd (Leigh 2013-11-09 12:00:00 1) First line.
    2365eb7d (Leigh 2013-11-09 12:00:10 2) Second line.
    

    The first bit is the commit ID, then name, then date, time, time zone, and finally the line number and line contents.

提交回复
热议问题