git-commit-as lets you choose which user to commit as, as specified in your git config
In a shell,
git commit-as John -m "Work committed by John"
git commit-as Megan -m "Add docs"
shows up in the git log as
Author: Megan <[email protected]>
Author: John Doe <[email protected]>
without having to modify git config between commands.
Scenario: You're on a shared computer, and you're using git. You commit. You notice it was committed under the name of the person that used the computer before you. You realize that's because you forgot to configure your name and email in git.
git-commit as makes sure you're committing as the right person.
Download the shell script, make it executable, and put in in your $PATH
.
For a user John, you would add this to your git config:
[users "John"]
name = "John Doe"
email = "[email protected]"
And they would commit with this command:
git commit-as John -m "Work committed by John"
The syntax is:
git commit-as <as-user> <arguments>
with arguments being the normal git commit arguments.
Refer to git commit-as --manual
for more information.
We get data from git config, and modify the environment variables GIT_AUTHOR_* and GIT_COMMITTER_*.
It won't override the git commit --author=<author> flag. That is useful when you only want to override the committer and want to specify the author.
I wrote the perl script first, and then translated it to shell. I tried limiting myself to POSIX commands and shell features, but it isn't an enforced rule.
Use shellcheck, and write good error messages.
Any contributions are appreciated, be it code, docs, typos or wording.