5

I would like to find the commit that added the following lines of code to solver.cpp for the deep learning library caffe, which is hosted on Github. I am not a contributor or have any special permissions. How do I do that?

template <typename Dtype>
void SGDSolver<Dtype>::ClipGradients() {
  const Dtype clip_gradients = this->param_.clip_gradients();
  if (clip_gradients < 0) { return; }
  const vector<shared_ptr<Blob<Dtype> > >& net_params = this->net_->params();
  Dtype sumsq_diff = 0;
  for (int i = 0; i < net_params.size(); ++i) {
    if (this->net_->param_owners()[i] < 0) {
      sumsq_diff += net_params[i]->sumsq_diff();
    }
  }
  const Dtype l2norm_diff = std::sqrt(sumsq_diff);
  if (l2norm_diff > clip_gradients) {
    Dtype scale_factor = clip_gradients / l2norm_diff;
    LOG(INFO) << "Gradient clipping: scaling down gradients (L2 norm "
        << l2norm_diff << " > " << clip_gradients << ") "
        << "by scale factor " << scale_factor;
    for (int i = 0; i < net_params.size(); ++i) {
      if (this->net_->param_owners()[i] < 0) {
        net_params[i]->scale_diff(scale_factor);
      }
    }
  }
}
5

First, you have to clone the repository to your machine:

git clone https://github.com/BVLC/caffe.git

Simply use git-blame to find out who committed a certain line:

git blame -L 123,123 path/to/file.cpp

Or, for a range of lines, use -L 100,150 or similar. You may want the option -M which detects if lines were moved.

You can also use git-log for the entire commit log:

git log -L 123,123:path/to/file.cpp
1

Responding to the title of this question specifically, rather than the description (as googling a search-phrase similar to the question title brought me here), I would recommend the following:

Clone the repository to your machine:

git clone https://github.com/BVLC/caffe.git

Then search the git log for all the commits where the search term is present:

git log -S searchTerm

Finally, tail the output in order to only see the oldest commit, as this must be the commit where that particular line was first added:

git log -S searchTerm | tail -4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.