Git常用操作

1.修改历史提交记录的作者和用户名

执行脚本安装 git-filter-repo

brew install git-filter-repo

在开始操作之前,建议先备份仓库,备份方式

  • git clone备份
git clone --bare https://github.com/your-username/your-repo.git your-repo-bare
  • cp -r指令复制整个文件夹
cp -r your-repo your-repo-backup

备份且安装完成后cd到项目目录下,替换下方的errorName和newName,以及error@mail.com和new@mail.com,执行脚本后将会替换掉本地所有的历史提交记录

git filter-repo --force --replace-refs delete-no-add \
    --commit-callback '
        if commit.committer_name == b"errorName":
            commit.committer_name = b"newName"
        if commit.committer_email == b"error@mail.com":
            commit.committer_email = b"new@mail.com"
        if commit.author_name == b"errorName":
            commit.author_name = b"newName"
        if commit.author_email == b"error@mail.com":
            commit.author_email = b"new@mail.com"
    '

而后强制推送到远端

git push --force origin main

如果出现如下错误信息,表示没有设置远端仓库地址

Aborting: Refusing to destructively overwrite repo history since
this does not look like a fresh clone.
(expected freshly packed repo)
Please operate on a fresh clone instead. If you want to proceed
anyway, use --force.

使用git remote -v查看是否正确设置了仓库地址

git remote -v

如果没有看到 origin 远程仓库,或者 URL 错误,你需要设置或更新它。

git remote add origin https://github.com/your-username/your-repo.git

而后再次尝试推送到远端

git push --force origin main
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值