1

I'm attempting to make a git alias to show all commits since the last tag. I'm basing it of this SO answer that I've used a lot in the past.

Currently, I'm trying this with a git config --global alias.* command like so:

git config --global alias.summary 'log `git describe --tags --abbrev=0`..HEAD --oneline'

This registers a new 'command' named 'summary' that would render out all the commit messages since the last tag.

However, when I run git summary, git throws out this error message:

fatal: ambiguous argument '`git': unknown revision or path not in the working tree.

Use '--' to separate paths from revisions, like this:

'git <command> [<revision>...] -- [<file>...]'

To me, this looks like the inner command git describe --tags --abbrev=0 that are nested inside the backticks do not evaluate correctly.

How can I fix this?

Community
  • 1
  • 1
matthewrdev
  • 11,930
  • 5
  • 52
  • 64
  • 1
    Possible duplicate of [What is the benefit of using $() instead of backticks in shell scripts?](http://stackoverflow.com/questions/9449778/what-is-the-benefit-of-using-instead-of-backticks-in-shell-scripts) – Ismail Badawi Feb 17 '16 at 21:55
  • Try `$(....)` in place of backticks. They nest. – Mark Setchell Feb 17 '16 at 22:18
  • Using `$()` when generating the alias results in the latest tag (if I'm in a repo) being embedded into the alias command; the desired behaviour is I can run `git summary` in any repository and it would list out all commits since the last tag. – matthewrdev Feb 17 '16 at 23:35

2 Answers2

1

EDIT: my original suggestion still holds, but check this out too: Git alias with shell variable expansions

I would suggest creating this as a bash function instead. I don't think Git is going to parse this correctly, and the net effect will be the same. You can add this to ~/.bashrc to have it automatically configured on shell startup.

gitsummary() {
    git log `git describe --tags --abbrev=0`..HEAD --oneline
}

You can execute bash functions as if they were standard apps, so like this

cd /my/git/dir
gitsummary
Community
  • 1
  • 1
Kevin Burdett
  • 2,892
  • 1
  • 12
  • 19
  • Using `$(...)` instead of backticks for command substitution obviates the need to define a shell function. – jub0bs Feb 17 '16 at 22:23
  • Thanks Kevin, while not exactly what I was after (as I'd prefer to just execute the command like it was a native git operation rather than a bash function) this did put me on the right path. – matthewrdev Feb 17 '16 at 23:43
1

I've figured out that you need to use the bang/! operator to flag to git that the alias should execute in the shell.

On a side note, replacing git describe --tags --abbrev=0 with $(git describe --tags --abbrev=0), causes the command to execute before it is placed into the [alias] section of the config file. This results in an alias command with the latest tag version being baked into the alias instead it dynamically finding the latest git tag.

IE: If a repository had the tags 1.1.0 and 2.0.0 and I attempted to add the alias a few commits on from 2.0.0, it would generate the following alias command:

'!git log 2.0.0..HEAD --oneline;'

This means 2.0.0 is now fixed as the tag to check against rather than dynamically finding the latest tag for the repository in question.

So, to fix my initial git alias, I needed to add !git to the start of the alias command:

git config --global alias.summary '!git log `git describe --tags --abbrev=0`..HEAD --oneline;'
matthewrdev
  • 11,930
  • 5
  • 52
  • 64