Git Memo - tenji/ks GitHub Wiki

Git 备忘录

一、代理设置

1.1 修改全局代理设置

git config --global http.proxy http://127.0.0.1:1080
git config --global https.proxy http://127.0.0.1:1080

git config --global --unset http.proxy
git config --global --unset https.proxy

1.2 修改当前项目代理设置

git config http.proxy http://127.0.0.1:1080
git config https.proxy http://127.0.0.1:1080

git config --unset http.proxy
git config --unset https.proxy

1.3 取消 SSL 认证

git config --global http.sslVerify false

二、修改提交作者和邮箱

2.1. 只最近一次提交

如果只需要最近一次提交,那么很简单直接使用git commit --amend就可以搞定:

git commit --amend --author="NewAuthor <[email protected]>"

2.2. 修改多次提交

如果是多个修改,那么就需要使用到git filter-branch这个工具来做批量修改

待补充。。。

2.3. 修改当前项目的作者和邮箱

git config --global user.name "YourName"
git config --global user.email "[email protected]"

三、修改注解模板

3.1. 设置当前全局注释模板

git config --globla commit.template [template_file_path]

3.2. 修改当前项目注释模板

git config commit.template [模板文件名]

3.3. 查询当前项目注释模板

git config commit.template

四、修改URL

4.1 由ssh修改为https

git remote set-url origin [url]

五、HTTP方式免密提交

  1. 新建文件并保存密码
vim ~/.git-credentials
  1. 添加内容
https://{username}:{passwd}@github.com
  1. 添加 git 配置
git config --global credential.helper store

六、迁移 Git 到新的仓库,且保存以前的提交记录

  1. 从原仓库 clone 一份裸版本库,比如原本托管于 GitHub,或者本地私有仓库
git clone --bare [origin-remote-git-address]
  1. 以镜像推送的方式提交到新服务器上
git push --mirror [target-remote-git-address]

七、恢复已提交到暂存区的删除文件

  1. 先将被删除文件从暂存区恢复到工作区
git reset HEAD [file-name]
  1. 从工作区恢复
git checkout -- [file-name]