git-log
is your friend here.
git log --pretty=oneline main.js | wc -l
git log also has some diff and patch related options. Do try
git log -p main.js
Edit: As Iamamac pointed out in the comment below, the above gives you the number of edits done to the file. What you truly want is the number of commits since the first check in of the file to the master. How about
git log master --oneline `git log master --reverse --pretty=%H main.js | head -1`..master | wc -l
This should work well in any branch. Thanks for asking this question. I have added a git-master-diff to my bin folder that contains
#!/usr/bin/env bash
git diff master~$(git log master --oneline `git log master --reverse --pretty=%H $@ | head -1`..master | wc -l ) $@
Should come in handy.