0

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.

Example

Original file:

user1
user2
user3

I then add

user4
user5

Then commit.

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

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

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.

|improve this answer|||||
2

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

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

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.