>_ IzzyLab

Hands-on task

This task is step 1 of the course “Git: rewriting and rescuing history”

Set up a git alias

easy~3 min

In /root/repo the last commit has the subject release v3.

Set up a git alias named last in this repository that outputs only the subject of the last commit. That is, the command git -C /root/repo last should print exactly the line release v3 (without the hash, date and the rest), and after a new commit — that commit's subject. It's enough to set up the alias locally for this repository.

What you'll practise:
  • git config
  • aliases
  • alias section
  • git log
  • output format

Topic breakdown

A git alias is an entry in the config in the [alias] section that maps a short name to an expanded command; it's set via git config by the key alias.<name>. Aliases can be local (for a single repository) or global, and you can bake any formatting flags into them. To get only the subject of a commit without the hash, date and author, git log has format placeholders and a limit on the number of commits. You can check the saved value via git config --get.

What's checked

  1. the last alias is set up
  2. the alias prints the subject of the last commit
  3. the alias works on a different history too

What it looks like