Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6a53d9f

Browse files
authored
Merge pull request #215 from pzelnip/gittotd
Post on git author & committer
2 parents 4a3cf2e + a33f00c commit 6a53d9f

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

content/gtotd-commit-vs-author.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
Title: Git Tip of the Day - Committer vs Author
2+
Date: 2021-08-06 11:28
3+
Modified: 2021-08-06 11:28
4+
Category: Posts
5+
tags: git,gitTipOfTheDay
6+
cover: static/imgs/default_page_imagev2.jpg
7+
summary: There's a distinction in git between committer and author. Lets learn about that.
8+
9+
So one thing that has always kinda puzzled me in Git is that when I'd `amend` a
10+
commit, then do a `git log` the timestamp for that commit seemed unchanged even
11+
though I've effectively "rewritten" that commit. I dug into this a bit today and
12+
learned about the distinction between Author and Committer which proved
13+
insightful around this.
14+
15+
The distinction is well summarized in the [Git
16+
docs](https://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History):
17+
18+
> You may be wondering what the difference is between author and committer. The
19+
> author is the person who originally wrote the work, whereas the committer is
20+
> the person who last applied the work.
21+
22+
So when you `amend` a commit you're updating the `committer` aspects of that
23+
commit and the `author` aspects remain unchanged. You can see both in Git log
24+
by using the `--format=fuller` argument:
25+
26+
```shell
27+
$ git log --format=fuller
28+
commit 9324ea7390b5c411c5cc050cf80965ce7425887a (HEAD -> foobar)
29+
Author: Adam Parkin <[email protected]>
30+
AuthorDate: Fri Aug 6 11:37:15 2021 -0700
31+
Commit: Adam Parkin <[email protected]>
32+
CommitDate: Fri Aug 6 11:37:15 2021 -0700
33+
34+
Test commit
35+
```
36+
37+
You can see in this that the commit in question was originally authored on
38+
August 6th, 2021 at 11:37AM (PST). Since this was the initial commit, the
39+
`CommitDate` is the same. But if we amend that commit & check again we'll see
40+
that the `CommitDate` is updated:
41+
42+
```shell
43+
$ git commit --amend
44+
[foobar 857e2a5] Test commit
45+
Date: Fri Aug 6 11:37:15 2021 -0700
46+
1 file changed, 0 insertions(+), 0 deletions(-)
47+
create mode 100644 content/gtotd-commit-vs-author.md
48+
49+
$ git log --format=fuller
50+
commit 857e2a58ac0fe3c295ab80efe4cf21f42986fcfb (HEAD -> foobar)
51+
Author: Adam Parkin <[email protected]>
52+
AuthorDate: Fri Aug 6 11:37:15 2021 -0700
53+
Commit: Adam Parkin <[email protected]>
54+
CommitDate: Fri Aug 6 11:38:34 2021 -0700
55+
56+
Test commit
57+
```
58+
59+
In this case the amend was also done by me, so the author & committer are the
60+
same.
61+
62+
If you want to update the `AuthorDate` you can do so with the `--date` option to
63+
`git commit`:
64+
65+
```shell
66+
$ git commit --amend --date 'now'
67+
[foobar d45d5f9] Test commit
68+
Date: Fri Aug 6 11:40:34 2021 -0700
69+
1 file changed, 0 insertions(+), 0 deletions(-)
70+
create mode 100644 content/gtotd-commit-vs-author.md
71+
72+
$ git log --format=fuller
73+
commit d45d5f9ea0579b6ea6fb4503a50abbac92a348a4 (HEAD -> foobar)
74+
Author: Adam Parkin <[email protected]>
75+
AuthorDate: Fri Aug 6 11:40:34 2021 -0700
76+
Commit: Adam Parkin <[email protected]>
77+
CommitDate: Fri Aug 6 11:40:34 2021 -0700
78+
79+
Test commit
80+
```
81+
82+
Here we can see that the use of `--date` set both `AuthorDate` and `CommitDate`
83+
to the same value (now).

0 commit comments

Comments
 (0)