A good way to do this is to use clean and grease filters to filter out selected lines as they are set. (The description below is essentially the same as the procedure described in this section of Pro Git, and which is very similar to the one in git attributes .) First of all, we need a command that deletes the lines between (and including) each debug:start and debug:end - fortunately, this is a simple job with sed :
sed '/debug:start/,/debug:stop/d' < foo.js
Now create a .gitattributes file at the top level of your git repository, which contains the following line:
*.js filter=strip-debug
And now determine what the strip-debug filter does both during cleaning (when setting) and when lubricating (when checked out):
git config filter.strip-debug.clean "sed '/debug:start/,/debug:stop/d'" git config filter.strip-debug.smudge cat
I (very briefly) checked this and seems to be doing what you want.
Mark longair
source share