Home Explore Blog CI



nushell

4th chunk of `cookbook/parsing_git_log.md`
044787e399deff6453503cc20fa8d1b1e8b55d8833c81b1500000001000012b7
Cool! Now that we have a real datetime we can do some interesting things with it like `group-by` or `sort-by` or `where`.
Let's try `sort-by` first

```nu
git log --pretty=%h»¦«%s»¦«%aN»¦«%aE»¦«%aD -n 25 | lines | split column "»¦«" commit subject name email date | upsert date {|d| $d.date | into datetime} | sort-by date
# => ────┬──────────┬──────────────────────────┬───────────────────┬───────────────────────────┬──────────────
# =>  #  │  commit  │         subject          │       name        │          email            │     date
# => ────┼──────────┼──────────────────────────┼───────────────────┼───────────────────────────┼──────────────
# =>   0 │ 0c3ea636 │ Add support for stderr   │ Sophia            │ 547158+sophiajt@users.nor │ 4 days ago
# =>     │          │ and exit code (#4647)    │                   │ eply.github.com           │
# =>   1 │ ed46f0ea │ fix: add missing         │ Jae-Heon Ji       │ 32578710+jaeheonji@user   │ 3 days ago
# =>     │          │ metadata for `ls_colors` │                   │ s.noreply.github.com      │
# =>     │          │ (#4603)                  │                   │                           │
# =>   2 │ 3eca43c0 │ Plugins without file     │ Fernando Herrera  │ fernando.j.herrera@gmai   │ 3 days ago
# =>     │          │ (#4650)                  │                   │ l.com                     │
# =>   3 │ 11bc0565 │ Find with regex flag     │ Fernando Herrera  │ fernando.j.herrera@gmai   │ 3 days ago
# =>     │          │ (#4649)                  │                   │ l.com                     │
# =>   4 │ d2bd71d2 │ add LAST_EXIT_CODE       │ LordMZTE          │ lord@mzte.de              │ 3 days ago
# =>     │          │ variable (#4655)         │                   │                           │
# =>   5 │ 799fa984 │ Update reedline, revert  │ Stefan Holderbach │ sholderbach@users.norep   │ 3 days ago
# =>     │          │ crossterm (#4657)        │                   │ ly.github.com             │
# =>   6 │ 995757c0 │ flags for find (#4663)   │ Fernando Herrera  │ fernando.j.herrera@gmai   │ 2 days ago
# =>     │          │                          │                   │ l.com                     │
# =>   7 │ 446c2aab │ Lets internals also      │ Sophia            │ 547158+sophiajt@users.nor │ 2 days ago
# =>     │          │ have exit codes (#4664)  │                   │ eply.github.com           │
# =>   8 │ 10ceac99 │ menu keybindings in      │ Fernando Herrera  │ fernando.j.herrera@gmai   │ 2 days ago
# =>     │          │ default file (#4651)     │                   │ l.com                     │
# =>   9 │ 4ebbe07d │ Polars upgrade (#4665)   │ Fernando Herrera  │ fernando.j.herrera@gmai   │ 2 days ago
# =>     │          │                          │                   │ l.com                     │
# =>  10 │ 78192100 │ Add shortcircuiting      │ Sophia            │ 547158+sophiajt@users.nor │ 2 days ago
# =>     │          │ boolean operators        │                   │ eply.github.com           │
# =>     │          │ (#4668)                  │                   │                           │
# =>  11 │ 796d4920 │ add char separators      │ Darren Schroeder  │ 343840+fdncred@users.no   │ 2 days ago
# =>     │          │ (#4667)                  │                   │ reply.github.com          │
# =>  12 │ 0f437589 │ add last exit code to    │ Darren Schroeder  │ 343840+fdncred@users.no   │ 2 days ago
# =>     │          │ starship parameters      │                   │ reply.github.com          │
# =>     │          │ (#4670)                  │                   │                           │
# =>  13 │ ef70c8db │ Date parse refactor      │ Jonathan Moore    │ jtm170330@utdallas.edu    │ 2 days ago
# =>     │          │ (#4661)                  │                   │                           │
# =>  14 │ 10364c4f │ don't use table          │ Sophia            │ 547158+sophiajt@users.nor │ a day ago
# =>     │          │ compaction in to nuon if │                   │ eply.github.com           │

Title: Sorting Git Log by Date in Nushell
Summary
The snippet demonstrates sorting git log entries by date in Nushell. It uses `git log` to retrieve commit information, then parses the output into a table. It converts the date strings into datetime objects and then sorts the entries using the `sort-by` command.