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

Harshal Kshatriya picture Harshal Kshatriya · Nov 9, 2013 · Viewed 32.7k times · Source

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

if (getListView().getChildCount() == 0)
                getActivity().findViewById(android.R.id.empty).setVisibility(View.VISIBLE);

How do I achieve this?

Answer

Rahil Ahmad picture Rahil Ahmad · Jul 1, 2017
git log -S searchTerm

gives you the commits in which the search term was introduced.