1

I want to create table with git commits in markdown but I don't know how create them. Note# The table needs full with the last commits or all.

2 Answers2

0

Note that, as mentioned in "Tables Generator"

As the official Markdown documentation (or CommonMark) states, Markdown does not provide any special syntax for tables. Instead it uses HTML <table> syntax.
But there exist Markdown syntax extensions which provide additional syntax for creating simple tables.

GFM (GitHub flavored Markdown) has such an extension.
So it depends first on the target environment which will have to display such a markdown table.

And you also need to limit/paginate your Git commit history (there can be a lot of commits in some repositories)

For instance, for the last 10 commits of the current branch:

#!/bin/bash

echo "| Commit Hash | Commit Message |"
echo "|----|-----|"

# Get the last 10 Git commits
commits=$(git log -n 10 --pretty=format:"%h %s")

# Loop through each commit and display the hash and message
while read -r commit; do
  hash=$(echo "$commit" | awk '{print $1}')
  message=$(echo "$commit" | awk '{$1=""; print $0}')
  echo "| $hash | $message |"
done <<< "$commits"
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Is correct, run in Git Bash but in the readme of github, no. i want to found insert git log in the readme in gthub. – Javier Santoyo Feb 06 '23 at 08:28
  • @JavierSantoyo Do yo mean the README of a Github repository of yours should include the last n commits, in a GitHub table, automatically refreshed whenever there is new commits? That would be tricky considering updating the README is in itself a commit. But I suppose not impossible through a GitHub Actions ([similar to this one](https://stackoverflow.com/a/72918091/6309)). – VonC Feb 06 '23 at 08:41
0

You can refer to James George's repo:

github-activity-readme

To understand more you can refer to: GitHub Activity: video by codeSTACKr

Here all the recent activities will be added automatically to readme.

Sakshi Sharma
  • 133
  • 1
  • 8