Home Explore Blog CI



nushell

14th chunk of `cookbook/parsing_git_log.md`
d8e02688b8bc90ee70794b496eb24b1d09d65ab8b2bb30df0000000100000c33
  │                                                                                                                              There isn't a column named 'date'
  │                                                                                                                              Perhaps you meant 'commit'? Columns available: commit, subject
```

Here's one tip for dealing with this error. We have a `do` command that has an `--ignore_errors` parameter. This is how you'd use it in the above example, if it were giving errors.

```nu
git log --pretty=%h»¦«%s»¦«%aN»¦«%aE»¦«%aD | lines | do -i { split column "»¦«" commit subject name email date } | upsert date {|d| $d.date | into datetime} | where ($it.date > ((date now) - 365day)) | group-by name | transpose
```

Now, back to parsing.
What if we throw in the `sort-by` and `reverse` commands for good measure? Also, while we're in there, let's get rid of the `[table 21 rows]` thing too. We do that by using the `length` command on each row of column1.

```nu
git log --pretty=%h»¦«%s»¦«%aN»¦«%aE»¦«%aD | lines | split column "»¦«" commit subject name email date | upsert date {|d| $d.date | into datetime} | where ($it.date > ((date now) - 365day)) | group-by name | transpose | upsert column1 {|c| $c.column1 | length} | sort-by column1 | reverse
# => ─────┬─────────────────────────────────┬─────────
# =>   #  │             column0             │ column1
# => ─────┼─────────────────────────────────┼─────────
# =>    0 │ Sophia                          │     851
# =>    1 │ Darren Schroeder                │     242
# =>    2 │ Fernando Herrera                │     176
# =>    3 │ Jakub Žádník                    │     136
# =>    4 │ Michael Angerman                │      61
# =>    5 │ Andrés N. Robalino              │      29
# =>    6 │ Luccas Mateus                   │      27
# =>    7 │ Stefan Stanciulescu             │      27
# =>    8 │ Sophia Turner                   │      23
# =>    9 │ Tanishq Kancharla               │      21
# =>   10 │ Justin Ma                       │      21
# =>   11 │ onthebridgetonowhere            │      20
# =>   12 │ xiuxiu62                        │      19
# => ...
```

This is still a lot of data so let's just look at the top 10 and use the `rename` command to name the columns. We could've also provided the column names with the `transpose` command.

```nu
git log --pretty=%h»¦«%s»¦«%aN»¦«%aE»¦«%aD | lines | split column "»¦«" commit subject name email date | upsert date {|d| $d.date | into datetime} | group-by name | transpose | upsert column1 {|c| $c.column1 | length} | sort-by column1 | rename name commits | reverse | first 10
# => ───┬────────────────────┬─────────
# =>  # │        name        │ commits

Title: Sorting, Limiting, and Renaming Git Commit Data in Nushell
Summary
This section builds upon the previous example by adding sorting and limiting functionalities. It demonstrates how to sort the grouped commit data by the number of commits, reverse the order, and display only the top 10 contributors using `sort-by`, `reverse`, and `first`. It also shows how to rename columns using the `rename` command, improving the clarity of the output.