git两个账号切换_Git切换账号方法
Windows修改Git账号打开控制面板(Win+s快捷键),输入:control命令行:control凭证管理器使用[凭证管理器]修改git账号:全局范围修改账号运行git config --global选项:$ git config --global user.name "John Doe"$ git config --global user.email "john@doe.org"项目范围修
Windows修改Git账号
打开控制面板(Win+s快捷键),输入:control
命令行:control
凭证管理器
使用[凭证管理器]修改git账号:
全局范围修改账号
运行git config --global选项:$ git config --global user.name "John Doe"
$ git config --global user.email "john@doe.org"
项目范围修改
针对项目修改git账号:$ git config user.name "John Doe"
$ git config user.email "john@doe.org"
单次提交修改作者
仅针对即将到来commit,可覆盖下一个提交者信息:git commit --author="John Doe "
--amend选项对最近一次提交执行修改。git commit --amend --author="John Doe "
git Interactive Rebase
这些都不能满足,可尝试 git Interactive Rebase。
可以完成任何事情,也意味着很容易搬石头砸自己的脚,使用前应先了解它。
第一步:
选择一个commit 记录(git log),将commit id传递给rebase命令:$ git rebase -i -p 0ad14fa5
命令会打开编辑器界面,使用“edit”关键字标记要更改的提交。
Git将引导完成提交,根据需要执行选择:Stopped at 5772b4bf2... Add images to about page You can amend the commit now, with
git commit --amend
Once you are satisfied with your changes, run
git rebase --continue
然后,修改作者信息。
完成后,继续执行下一个提交对象,直至编辑完标记的所有提交:$ git commit --amend --author="John Doe " --no-edit
$ git rebase --continue
git filter-branch批量修改
Git filter-branch允许使用脚本批量处理提交,可在git仓库中运行如下示例(填写新旧电子邮件和名称):$ git filter-branch --env-filter '
WRONG_EMAIL="wrong@example.com"
NEW_NAME="New Name Value"
NEW_EMAIL="correct@example.com"
if [ "$GIT_COMMITTER_EMAIL" = "$WRONG_EMAIL" ]
then
export GIT_COMMITTER_NAME="$NEW_NAME"
export GIT_COMMITTER_EMAIL="$NEW_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$WRONG_EMAIL" ]
then
export GIT_AUTHOR_NAME="$NEW_NAME"
export GIT_AUTHOR_EMAIL="$NEW_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags
在使用前需有清楚的认识。
手动修改账号
在执行了常规命令后,提交记录仍未见效,可尝试修改项目.git\logs目录下日志记录,手动修改对应分支日志文件。.git\logs\HEAD
.git\logs\refs\heads\master
.git\logs\refs\heads\分支名
注:只是应急策略。
更多推荐
所有评论(0)