Parse Git Log by Modified Files

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

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

Elena Rostova
Author

Elena Rostova

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.