I'd like to filter the content of a log of a pom.xml
file using a regex.
I created it on regexr and it works using PCRE; this is my regex:
commit \K[a-z0-9]*(?=[\s\S]*\+.*<version>1.2.0)
I then tried to run with the following commands:
git log --full-history -p pom.xml | grep -P "commit \K[a-z0-9]*(?=[\s\S]*\+.*<version>1.2.0)"
and
git log --full-history -p pom.xml | perl -nle 'print \$1 if /commit \K[a-z0-9]*(?=[\s\S]*\+.*<version>1.2.0)/'
but neither of them worked (nothing seems to match).
I'm surely missing something, but I cannot figure out what.
EDIT:
To clarify, this is an example of git log
:
commit a1357f4e1cb2c34aa1a1357f4e1cb2c34aa1471f
Author: Author <[email protected]>
Date: Wed Mar 30 15:04:29 2022 +0100
commit message
diff --git a/pom.xml b/pom.xml
index 93df07e..5f82fd2 100755
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.organization.project</groupId>
<artifactId>ProjectName</artifactId>
- <version>1.1.1</version>
+ <version>1.2.0</version>
<name>ProjectName</name>
<description>Description of project</description>
I want to pick the hash of the commit where version
changed to a certain value (1.2.0
in the regex I wrote).
Obviously, this being the log of all the commits done on a certain repository, there may be more than one commit as well.
Using the aforementioned regex on this input should output the commit hash:
a1357f4e1cb2c34aa1a1357f4e1cb2c34aa1471f
This is what actually happens using regexr.
git log… | awk '$1=="commit" {print $2}'
? Presumably I'm missing something so please could you edit your question to clarifygit log
. Perhaps you could edit your question to extend the example to include one (or two) pom.xml commits along with one or two different commits.