Parse git log by modified files

I have been told to make git messages for each modified file all one line so I can use grep to find all changes to that file. For instance:

$git commit -a modified: path/to/ - 1) change1 , 2) change2, etc......
$git log | grep path/to/ modified: path/to/ - 1) change1 , 2) change2, etc...... modified: path/to/ - 1) change1 , 2) change2, etc...... modified: path/to/ - 1) change1 , 2) change2, etc......

That's great, but then the actual line is harder to read because it either runs off the screen or wraps and wraps and wraps.

If I want to make messages like this:

$git commit -a modified: path/to/ 1) change1 2) change2 etc......

is there a good way to then use grep or cut or some other tool to get a readout like

$git log | grep path/to/ modified: path/to/ 1) change1 2) change2 etc...... modified: path/to/ 1) change1 2) change2 etc...... modified: path/to/ 1) change1 2) change2 etc......
1

1 Answer

If the output of grep command shows like this,

$ git log | grep path/to/ modified: path/to/ - 1) change1 , 2) change2, etc...... modified: path/to/ - 1) change1 , 2) change2, etc...... modified: path/to/ - 1) change1 , 2) change2, etc......

Then you can pipe it to the below awk command to produce the desired output,

git log | grep path/to/ | awk -v RS='[-,]' '{print}'

Example:

$ cat aa modified: path/to/ - 1) change1 , 2) change2, etc...... modified: path/to/ - 1) change1 , 2) change2, etc...... modified: path/to/ - 1) change1 , 2) change2, etc......
$ awk -v RS='[-,]' '{print}' aa modified: path/to/ 1) change1 2) change2 etc...... modified: path/to/ 1) change1 2) change2 etc...... modified: path/to/ 1) change1 2) change2 etc......
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like