Authors are the people who wrote a specific piece of code - committers are the people who put these changes into the git "history". Normally both are the same (and doesn't change on merging, cloning, pushing or pulling).
The git commit --amend --reset-author --no-edit command is especially useful if you created commits with the wrong author information, then set the correct author after-the-fact via git config .
The original poster asks:
What is the difference between the two (Committer vs author)?
The author is the person who originally wrote the code. The committer, on the other hand, is assumed to be the person who committed the code on behalf of the original author. This is important in Git because Git allows you to rewrite history, or apply patches on behalf of another person. The FREE online Pro Git book explains it like this:
You may be wondering what the difference is between author and committer. The author is the person who originally wrote the patch, whereas the committer is the person who last applied the patch. So, if you send in a patch to a project and one of the core members applies the patch, both of you get credit — you as the author and the core member as the committer.
The original poster asks:
Should I be setting the committer as well to the other user?
No, if you want to be honest, you should not be setting the committer to the author, unless the author and the committer are indeed the same person.
Mailing list + git format-patch
+ git apply
can generate author != committer
In projects like the Linux kernel where patches are:
git format-patch
git send-email
git apply
or git am
: How to use git am to apply patches from email messages?
generating a single new commit with different author and committer:
See for example this randomly selected patch and the corresponding commit:
Git web interfaces like GitHub and GitLab may or may not generate author != committer
Since Git(Hub|Lab) hold both the upstream and the fork repositories on a the same machine, they can automatically do anything that you can do locally as well, including either of:
Create a merge commit.
Does not generate author != committer.
Keeps the SHA or the new commit intact, and creates a new commit:
* Merge commit (committer == author == project maintainer)
|\
| * Feature commit (committer == author == contributor)
|/
* Old master (random committer and author)
Historically, this was the first available method on GitHub.
Locally, this is done with git merge --no-ff
.
This produces two commits per pull request, and keeps a fork in the git history.
rebase on top of master
GitHub also hacks the commits to set committer == whoever pressed the merge button. This is not mandatory, and not even done by default locally by git rebase
, but it gives accountability to the project maintainer.
The git tree now looks like:
* Feature commit (committer == maintainer, author == contributor)
|
* Old master (random committer and author)
which is exactly like that of the git apply
email patches.
On GitHub currently:
https://help.github.com/articles/about-merge-methods-on-github/
How to set the committer of a new commit?
The best I could find was using the environment variables to override the committer:
GIT_COMMITTER_NAME='a' GIT_COMMITTER_EMAIL='a' git commit --author 'a <a>'
How to get the committer and commit date of a given commit?
Only author data shows by default on git log
.
To see the committer date you can either:
format the log specifically for that:
git log --pretty='%cn %cd' -n1 HEAD
where cn
and cd
stand for Committer Name
and Committer Date
use the fuller
predefined format:
git log --format=fuller
See also: How to configure 'git log' to show 'commit date'
go low level and show the entire commit data:
git cat-file -p HEAD
How to set the committer date of a new commit?
git commit --date
only sets the author date: for the committer date the best I could find was with the environment variable:
GIT_COMMITTER_DATE='2000-01-01T00:00:00+0000' git commit --date='2000-01-01T00:00:00+0000'
See also: What is the difference between author and committer in Git?
How Git stores author vs committer internally?
See: What is the file format of a git commit object?
Basically, the commit is a text file, and it contains two line separated fields:
author {author_name} <{author_email}> {author_date_seconds} {author_date_timezone}
committer {committer_name} <{committer_email}> {committer_date_seconds} {committer_date_timezone}
This makes it clear that both are two completely independent data entries in the commit object.
@Ciro Santilli proposed to use
GIT_COMMITTER_NAME='a' GIT_COMMITTER_EMAIL='a' git commit --author 'a <a>'
If you accidentally used different names and emails, and you want to set the to the same values:
GIT_COMMITTER_NAME='a'; GIT_COMMITTER_EMAIL='a'; git commit --author "$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
which first sets the variables in separate commands, then uses them for the git commit
call (note the double parentheses).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With