I want to write shell script to parse java source files and find-out the common violations in source code based on some rule. This script should run on new code which is added/modified , this shouldn't get the old code. My code repository is git.
How to get the newly added/modified lines from git. I can then execute my script on top this.
If you want to apply some parsing action on code, you are probably better off parsing whole files rather than spotting only the modified lines. On top of that, the notion of "added line" depends a lot on the heuristic implemented in
diff
, and will often give you results that don't match what you would expect.I didn't get the context from your question, especially what you intend to compare :
git diff --name-only
orgit diff --name-status
:If you need to target merge commits (which have more than one parent),
git show
tries to be smart and may give you better results :If you really want just the modified/added lines : just grep them from
git diff
for each modified file, run something like :