Home » Git » How to put git log results in an array of arrays? Powershell/ GitBash

How to put git log results in an array of arrays? Powershell/ GitBash

Posted by: admin November 22, 2021 Leave a comment

Questions:

For a specific branch I would like to;

Run the Git Log command to get the Commit and Filename, this will be executed in Powershell.

I then would like to have For Loop to go through the Commits and have the last Modified filename in a 1 dimensional table, i can use the join cmd in Powershell to join Commit and Filename together.

Example of the Output would be;

Commit Filename

14241jdae FileOne.ps1

24242jdae FileTwo.ps1

34243jdae FileThree.ps1

The problem i am having if i run the following

git log branch1 –pretty=oneline

This displays the result, even if i use a function and call the function, i am struggling how to assign the Git Log output to a 1-Dimensional Array or 2-Dimensional Array table format.

Any help would be appreciated.

Answers:

You could start with a git log <branchName> --name-status --oneline and then parse that output. The first line is the short commit id followed by short commit message. Following lines start with A|C|D|M|R|T|U|X|B and that will be the change type followed by the filename – shouldn’t be hard to parse in any scripting language, take your pick (Python/PERL,….). (See the –diff-format section of http://git-scm.com/docs/git-log for the diff-stat flags).