Creating a Git Alias ​​That Gets the Last Commit

I am wondering if there is a way to get the SHA1 of the last commit via a Git alias.

I have the following so far, but it is throwing an error:

Error extending the alias "last-commit"; '9fa5c2c72e586ce825d54114532400d8cc56106f' is not a Git team

The command I use to create an alias last-commit:

git config --global alias.last-commit `log -1 --pretty=format:%H`

I know that it git log -1will provide me with the latest commit information, but I want the latest SHA1 commit on its own, so I can use it with cat.

Any help is appreciated

+3
source share
2 answers

You can do:

git rev-parse HEAD

... or as an alias:

$ git config --global alias.last-commit "rev-parse HEAD"
$ git last-commit
dc1ac14864ecb3dd27f934ba964b030cfedf234a

manojlds , , - , backquotes , . log, , , , . .

+4

git rev-list -1 HEAD

, git log, :

git config --global alias.last-commit "log -1 --pretty=format:%H"

.

+3

All Articles