The command:
git log --oneline --name-status
--author=$AUTHOR $COMMIT_RANGE | grep -vE '[a-fA-F0-9]{5} '
| sort | uniq | cat -n
Returns a list of the files modified by an author between a range of commits with the status e.g. M
for modified.
1 M a_file
2 M another_file
3 M file
4 D file
How can I show only the last thing that happened to the file file
, e.g. here it was deleted (D
)?
I don't want to see the previous modifications to the file (i.e. the M
), only the last thing that happened in that range of commits.
Thanks for the attention!
You can tweak
uniq
to look only at a certain field:I used
tac
as well to reverse the output again. You can leave it out though. Also it's a GNU utility which you won't find on BSD / OS X machines.This is the command I ended up with which works for me:
Where
$AUTHOR
is the author name and $COMMIT_RANGE is a range of commits in the formOLDER_COMMIT_SHA1..NEWER_COMMIT_SHA1
(HEAD can be used too for NEWER_COMMIT_SHA1).Command explanation:
git log
output withgrep -vE
, I number each line withcat -n
;git
inserts when using--name-status
and the initial spaces inserted bycat -n
withsed -e 's/ / /g' | sed -e 's/^ *//g'
;cat -n
result). This way I keep the first occurrence of the filename which is the one I'm interesting in;uniq
will return the first occurrence of a new filename first an will not repeat the other occurrences of the same filename; but at the same time the first filename for each 'group' is the one I'm interested in because it has the last--name-status
flag I'm interested in and it tells me what's the last thing that happened on that file (was it a modification? A deletion? etc...);uniq
command and count again.I want to thank
codeWizard
,Arne
andVonC
for theuniq -f
advice which helped me to work out the solution.Here is what you want to do:
What have i modified:
sort -r
reverse the sorting so the result will printed in reverse order
head -1
Take the first line of the result
uniq -f 1
Get the
uniq
values skipping the first row which is the counter so it cant be unique.