How to get the "committer" information that Git will use

Reading the document, I see that I could predict what Git would use as a "committer" by combining git config user.name and git config user.email along with $GIT_COMMITTER_NAME and $GIT_COMMITTER_EMAIL . But when I write code that does this, I get the feeling that I am rewriting a piece of code that is already in Git, and I would rather reuse Git's own code for this.

So, as I prefer to use git rev-parse --git-dir rather than looking for .git and / or checking $GIT_DIR , I would like to use a command like git show-me-the --committer to get the usual NAME <EMAIL> >> string. However, I could not find this in the manual (s).

+5
source share
1 answer

You can use the git var command:

 git var GIT_COMMITTER_IDENT 

It can be run outside of any Git workspace, prints committer information in the format name <email> timestamp timezone and uses the same Git code that also runs when committed, therefore respects configuration keys and environment variables. Depending on what you want to do with this information, you may need to filter out the timestamp and time zone.

+8
source

Source: https://habr.com/ru/post/1239594/


All Articles