git log - Get list of tasks numbers from git log based on message -
task number = jira issue number = **** (e.g.: 7600)
let's suppose have list of commits having following messages:
prj-7600 - first message prj-8283 - second message prj-8283 - third message prj-1001 - fourth message prj-8283 - fifth message prj-7600 - sixth message
where first 1 oldest commit.
wanted output:
1001 7600 8283
i listed commits using following command:
git log --author="first last" --oneline --grep=prj --pretty=format:"%s" | sort
where
- committer = author (in case)
--grep=prj
specified ignore comments automatically generated ("merge branch ...") (alternative--no-merges
)--pretty=format:"%s"
shows message (removes hash)
actual output:
prj-1001 - fourth message prj-7600 - first message prj-7600 - sixth message prj-8283 - fifth message prj-8283 - second message prj-8283 - third message
is possible extract numbers (probably using regex or substring) showing them once?
details:
- windows 7
- git 1.9.5 (msysgit) -> used cmd, not git bash console
this in either bash or git bash:
git log --author="first last" --oneline --grep=prj --pretty=format:"%s" | sort | cut --delimiter='-' --fields=2 | uniq
so building on first section posted in question, is:
| cut --delimiter='-' --fields=2 | uniq
this pipes sorted output cut
extracts 2nd field delimited hyphen "-" , result pipes uniq
display distinct values.
this solution has weakness in form of delimiter used cut
- if format of log message changes, may break. better solution use regex search (instead of cut
) issue key ("/prj-.+\s/" think...) , output number part.
edit
so after bit of digging, possible little more reliably using grep
find item key (prj in case):
git log ... | grep -op --regexp="prj-\k\d+" | uniq
-o
tells grep output matched part of line
-p
use pcre (perl/php) flavour of regex, enabling use the
\k
option causes matches prior (to point) excluded
Comments
Post a Comment