0

Is it possible to create a git alias to do a less style display of a specific file from the last commit?

The usual command for that would be git show HEAD~0:FileName.

However creating an alias like this sh-la = show HEAD~0: and running it with git sh-la FileName does not work.

1
  • Why the -1? I made sure there were lots of git questions here before asking. Commented Jun 4, 2016 at 16:22

1 Answer 1

1

The problem is that you would need the filename concatenated directly after HEAD~0:. With a simple alias that's not what happens with extra arguments. In your example this will be executed:

git show HEAD~0: FileName

Notice the space after HEAD~0:.

To achieve what you want, you need use a function, like this:

sh-la = "!f() { git show HEAD~0:\"$1\"; }; f"
Sign up to request clarification or add additional context in comments.

1 Comment

I see. Thanks very much, your function alias works perfectly. I had no idea that git aliases beginning with a ! call an external command, what a useful feature.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.