Git学习笔记

1.不再允许SHA-1

1.1 问题描述

>> ERROR: You're using an RSA key with SHA-1, which is no longer allowed. Please use a newer client or a different key type.

1.2 解决办法

  • (1) 生成新版ssh-key
>> ssh-keygen -t ecdsa -b 521 -C "email"
  • (2) 打印生成的ssh-key
>> cat ~/.ssh/id_rsa.pub
  • (3) 将生成ssh-key添加到git上即可

1.3 参考资料

  • [1] https://blog.csdn.net/Mr_kanger/article/details/123741702

2.配置git的用户名和邮箱

2.1 配置git的用户名

>> git config --global user.name "用户名"

2.2 配置git的邮箱

>> git config --global user.email "用户邮箱"

3.删除远程不存在的git分支

>> git remote prune origin

4.查看当前git存在的分支

>> git branch -a

5.切换git的分支

>> git checkout [分支名]

6.删除git分支

6.1 删除本地分支

>> git branch -D [分支名]
>> git branch -delete [分支名]

前一个是强制删除

6.2 删除远程分支

>> git push origin --delete [分支名]

7.拉去git远程代码

>> git pull

8.推送代码到git远程

>> git push

9.设置git远程仓库地址

>> git remote set-url origin [git地址]

10.拉去远程git项目及子模块

>> git clone --recursive [git地址]

11.无痕回撤掉git记录

>> git reset --hard HEAD~[N条记录]
>> git push -f origin

12.批量修改git记录

#!/bin/sh

>> git filter-branch --env-filter '

OLD_EMAIL="原邮箱地址"
CORRECT_NAME="新用户名"
CORRECT_EMAIL="新邮箱地址"

if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_COMMITTER_NAME="$CORRECT_NAME"
    export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$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 origin --force --all
>> git update-ref -d refs/original/refs/heads/master

参考资料

(1) [Github实战]批量修改git commit记录中的用户名和邮箱


版权声明:本文为sinat_31425585原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。