孙建嘉优秀作者
原创内容 来源:小居数码网 时间:2024-08-10 20:22:01 阅读() 收藏:48 分享:60 爆
导读:您正在阅读的是关于【数码知识】的问题,本文由科普作家协会,生活小能手,著名生活达人等整理监督编写。本文有666个文字,大小约为3KB,预计阅读时间2分钟。
背景由于 Github 和公司 Git 使用账号不一样,偶尔没注意,提交出错后就需要修改 commit 信息。
# 修改最近提交的 commit 信息$ git commit --amend --message="modify message by daodaotest" --author="jiangliheng <jiang_liheng@163.com>"# 仅修改 message 信息$ git commit --amend --message="modify message by daodaotest"# 仅修改 author 信息$ git commit --amend --author="jiangliheng <jiang_liheng@163.com>"
操作步骤:
# 列出 rebase 的 commit 列表,不包含 <commit id>$ git rebase -i <commit id># 最近 3 条$ git rebase -i HEAD~3# 本地仓库没 push 到远程仓库的 commit 信息$ git rebase -i# vi 下,找到需要修改的 commit 记录,```pick``` 修改为 ```edit``` 或 ```e```,```:wq``` 保存退出# 重复执行如下命令直到完成$ git commit --amend --message="modify message by daodaotest" --author="jiangliheng <jiang_liheng@163.com>"$ git rebase --continue# 中间也可跳过或退出 rebase 模式$ git rebase --skip$ git rebase --abort
创建批量脚本changeCommit.sh:
$ cat changeCommit.sh#!/bin/shgit filter-branch --env-filter '# 之前的邮箱OLD_EMAIL="jiangliheng@126.com"# 修改后的用户名CORRECT_NAME="jiangliheng"# 修改后的邮箱CORRECT_EMAIL="jiangliheng@163.com"if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]then export GIT_COMMITTER_NAME="$CORRECT_NAME" export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"fiif [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]then export GIT_AUTHOR_NAME="$CORRECT_NAME" export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"fi' --tag-name-filter cat -- --branches --tags
执行脚本成功后,强制推送到远程服务器:
$ git push --force --tags origin 'refs/heads/*'
上面就是小居数码小编今天给大家介绍的关于(直接修改git上的commit信息)的全部内容,希望可以帮助到你,想了解更多关于数码知识的问题,欢迎关注我们,并收藏,转发,分享。
94%的朋友还想知道的:
(464)个朋友认为回复得到帮助。
部分文章信息来源于以及网友投稿,转载请说明出处。
本文标题:Git修改已提交commit的信息(直接修改git上的commit信息):http://sjzlt.cn/shuma/154499.html