I have a list of usernames that are in a text file. I update this file and commit it. I am looking for a way to get a list of the changes since the last commit.

I do not want any diff formatting at all, I just want to get an output that has usernames one per line (as they are added to each commit) since the last commit.

I can't find a setting that will remove all the git diff syntax from the output so it's purely a list new lines added only.


Original file:


I then add


Then commit.

I want to be able to do a git diff and see only:

  • This question shows how to do this with GNU diff, but git diff doesn’t support the relevant options. Jun 15 '18 at 10:52

You could grep the diff output combining lookahead/lookbehind:

git diff --unified=0 | grep -Po '(?<=^\+)(?!\+\+).*'
  • (?<=^\+) is a positive lookbehind for line starting with +
  • (?!\+\+) is a negative lookahead to prevent matching files headers starting with +++ a/path/to/file.

The --unified=0 git option is just there to reduce the numbers of line to filter removing diff context, it is optional though.

There is probably better, I'm not fluent in PCRE.


Borrowing --unified=0 from kaiko answer I came to:

git diff HEAD^ HEAD --unified=0 | tail +6 | sed -e 's/^\+//'

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.