Reputation: 3826
I am attempting to rename all commits' authors in a local repository before uploading to GitHub, but I get an error if the name contains a space. The repository was not originally configured with a name and all commits are from the same user.
Here is the script I have been using:
git filter-branch --commit-filter '
GIT_AUTHOR_NAME="FirstName LastName";
GIT_AUTHOR_EMAIL="[email protected]";
GIT_COMMITTER_NAME="FirstName LastName";
GIT_COMMITTER_EMAIL="[email protected]";
git commit-tree "$@";' HEAD
And the error that results:
fatal: ambiguous argument 'LastName;
[email protected];
GIT_COMMITTER_NAME=FirstName': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
I have attempted to resolve the issue by escaping the space with \
however I have only been able to successfully run the script by removing the space, e.g. FirstName LastName
becomes FirstNameLastName
Upvotes: 0
Views: 1186
Reputation: 597
An additional solution which is working on powershell core:
param(
[Parameter(Mandatory = $true)]
[string]
$name,
[Parameter(Mandatory = $true)]
[string]
$email
)
$command = @"
GIT_COMMITTER_EMAIL='$mail';
GIT_AUTHOR_EMAIL='$mail';
GIT_COMMITTER_NAME='$name';
GIT_AUTHOR_NAME='$name';
git commit-tree "$@";
"@
& git filter-branch -f --commit-filter $command head
Upvotes: 0
Reputation: 3826
Seems to be an issue with Powershell on Windows. After switching to Git Bash the script ran correctly with the spaces.
Upvotes: 0
Reputation: 35358
Try
git filter-branch --commit-filter "
GIT_AUTHOR_NAME='FirstName LastName';
GIT_AUTHOR_EMAIL='[email protected]';
GIT_COMMITTER_NAME='FirstName LastName';
GIT_COMMITTER_EMAIL='[email protected]';
git commit-tree ""$@"";" HEAD
I changed the " to ' and vice versa and added double quotes around $@
Upvotes: 1