Author and Committer in Git

One of the most popular Version Control System is git. Git is created by Linus Torvalds as a tool to work with linux kernel source code.

The most important thing in git is a thing called "commit".

Here is an example. I create a new directory, make it a git working copy, create empty README.md file and create a commit:

$ mkdir repo/; cd repo/; git init; touch README.md; git add README.md; git commit -m "Initial commit"
Initialized empty Git repository in /Users/bessarabov/repo/.git/
[master (root-commit) c612318] Initial commit
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 README.md

From the output you can see the ID of commit: c612318 (actually it is just first 7 chars of ID).

It is possible to get the raw data of commit. It is how the commit is stored internally in git. It is a command that you don't need in your day-to-day work with git, but this command is very useful to show that in commit there is such things as "author" and "committer:

$ git cat-file commit c612318
tree f93e3a1a1525fb5b91020da86e44810c87a2d7bc
author Ivan Bessarabov <ivan@bessarabov.ru> 1565384565 +0300
committer Ivan Bessarabov <ivan@bessarabov.ru> 1565384565 +0300

Initial commit

The commit data is just a plain text. The first word in a line is the key, the rest of the line is a value for that key (is some cases the value can be multiline). After all the key-value pairs there is an empty line and after that there is the commit message.

The first key is "tree". The value is the ID that defines all the file structure and the content of the files. Next there are two lines with author & committer info. There is name, email, timestamp and timezone. In this example the author and committer are the same.

We can see that in git commit there is an "author" and "committer". The idea is that the "author" is the person who writes the code. And the "committer" is the person who is responsible for putting commit into the repository.

Most of the times the author and committer fields are the same. But there are some situations when they can differ.

Creating commit in GitHub web interface

GitHub has a great feature. You can edit files in the browser without the need to clone the repo.

On the file page you need to press on pencil icon:

GitHub file control icons

Then make the changes and create a commit:

GitHub web interface commit interface

Here is a raw data for commit I make via web interface:

$ git cat-file commit 5d5ebc7
tree 81ab2295d950bcd83d11ab1ad088de8210d5b79e
parent c61231888fe128ac6626cf0fff5593b0bc8b33bc
author Ivan Bessarabov <ivan@bessarabov.ru> 1565385298 +0300
committer GitHub <noreply@github.com> 1565385298 +0300
gpgsig -----BEGIN PGP SIGNATURE-----

 wsBcBAABCAAQBQJdTeJSCRBK7hj4Ov3rIwAAdHIIAJIlndl4U8kKW+VvvTtkzHK9
 Gh9J2JnefRHMskfGJg3DpNQymGus5BsxxjnZvLFRALK8dxn81v7C+6NpT1mRyT16
 BzOBJ6slg5ZFKC6SqqJ1JGhjSSrhEJa71fx8XA0j1KmLo9zRAfYY7+X8RfXcZcjP
 pt+/lZ15xfN3jakK3B2un1jx7gijGo9B6PNZkEx88Yyw077Vrl3Ey7XO9LK/Dffy
 hl4IBp5KuNsziYL0PlmFNJ6CYk4xMDoYNdwbO5JAaetze1/j7QIdx/Mq/rkAS+wE
 gdnK335S3+HS++Ixu+eX4enwo5XwwkKISs0F6oCiC7rcI2wJl0BrSgO3pMcqz6k=
 =iKHm
 -----END PGP SIGNATURE-----


Update README.md

There are some differences from the previous raw commit. The most visible is the block with PGP signature. It guarantees that the commit was made in GitHub interface (but I can't guarantee that is is done by that person, maybe his GitHub login/password was stolen):

GitHub Verified Commit

Next there is a line starting with "parent" — it is ID of the previous commit (in the first example there was no parent because it was the first commit in the repo).

And the most interesting thing in the context of this text is that the author and committer differ. The author is me, but the committer is GitHub. It means that the commit was made in the GitHub web interface.

Pull Request

The very common approach to propose a change in open source software in GitHub is to create Pull Request.

Here is an example of the small change I did recently. I forked repo and created a comit in my own repo:

$ git cat-file commit 2d6079523b45be9af1d26bcefc453325a7f83500
tree a152ad7cbe81f9929b50facbb283b96ca2eaa19c
parent 3ec9d0d8b258ccd6a9bee542b8c657cf5b54fdc5
author Ivan Bessarabov <ivan@bessarabov.ru> 1565555421 +0300
committer Ivan Bessarabov <ivan@bessarabov.ru> 1565555421 +0300

Fixing indent in README.md

Then I have created Pull Request with that change. After Pull Request was approved, slightly different commit has appeared in the original repo:

$ git cat-file commit f77ad01fbfefa466282eb1f606fe39471a0171fc
tree a152ad7cbe81f9929b50facbb283b96ca2eaa19c
parent 3ec9d0d8b258ccd6a9bee542b8c657cf5b54fdc5
author Ivan Bessarabov <ivan@bessarabov.ru> 1565555421 +0300
committer Umputun <umputun@gmail.com> 1565557295 -0500

Fixing indent in README.md

GitHub has changed the commiter to contain the information about the person who has approved Pull Request.

GitHub web interface shows that info:

GitHub commit info about author and committer

How to specify committer when making a commit

When you make commit in console there is a way to specify committer info. To do it you need to set environment variables. Here is an example:

$ GIT_COMMITTER_NAME='Some name' GIT_COMMITTER_EMAIL='email@example.com' git commit -m "Commit with some committer"
[master 26623e1] Commit with some committer
 Author: Ivan Bessarabov <ivan@bessarabov.ru>
 1 file changed, 1 insertion(+)

When we check the raw commit data we can see that the committer has the information we have specified:

$ git cat-file commit 26623e1
tree 92bf9193f40e4510f10c592781511956625ce042
parent 5d5ebc70f4c9d7466dc98ded0027cc9b4d70c3d8
author Ivan Bessarabov <ivan@bessarabov.ru> 1565430885 +0300
committer Some name <email@example.com> 1565430885 +0300

Commit with some committer

Using --author option

Another way to make commit with different author & committer is to use "--author" option when making a commit.

Here is I'm creating commit specifying Some User as the author. But! In by global .gitconfig there is different name and email.

$ git commit -m "Changes" --author "Some User <user@example.com>"
[master e186152] Changes
 Author: Some User <user@example.com>
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a.txt

When we check the raw commit info we'll see that its author is what we have specified, but the committer is my name & email from global .gitconfig:

$ git cat-file commit e186152
tree ea8a2779933608b11c091039cfe8cf390d469c35
parent 26623e10d57c0ff9ba97ec45d5ec050d151c6b6b
author Some User <user@example.com> 1565437028 +0300
committer Ivan Bessarabov <ivan@bessarabov.ru> 1565437028 +0300

Changes

So if you need to create commit with some other name make sure to to use environment variable to set committer (as it is described in the previous section), or set the name/email to what you need (don't forget to change it back):

git config --global user.name "Ivan Bessarabov"
git config --global user.email "ivan@bessarabov.ru"

Using a patch

The other was to create commit with different author and committer is to apply path with command "git am". The patch is created with the command "git format-patch".

Ivan Bessarabov
ivan@bessarabov.ru

12 august 2019