git命令

  • git记录删除动作:rm <file> + git commit -am "abc"git rm <file> + git commit -m "abc"
  • 不再同步相关文件:本地缓存删除(改变成未track状态)git rm -r --cached filename,然后再修改.gitignore文件
  • 使用windows凭据管理器管理密码,git config --global --add credential.helper manager
  • git 强制pushgit push origin master --force

git设置代理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
git config --global https.proxy http://127.0.0.1:1080

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

git config --global --unset http.proxy

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

//对于使用git@协议的,可以配置socks5代理
//在~/.ssh/config 文件后面添加几行,没有可以新建一个

//socks5
Host github.com
User git
ProxyCommand connect -S 127.0.0.1:1080 %h %p

//http || https
Host github.com
User git
ProxyCommand connect -H 127.0.0.1:1080 %h %p

linux

1
2
3
Host github.com
User git
ProxyCommand nc -X 5 -x 127.0.0.1:7891 %h %p

-X 5可以省略,因为是默认值

多用户设置

在~/.ssh/config 文件后面添加几行,并重新进入命令行生效

1
2
3
4
5
6
7
Host qwe
HostName github.com
IdentityFile ~/.ssh/id_ed25519

Host adas # 前缀名可以任意设置
HostName github.com
IdentityFile ~/.ssh/id_rsa

remote origin url改为

1
git remote set-url origin git@adas:*/*.git

git@qwe:**/**.git

git@adas:**/**.git

配置ssh密钥到git服务器

cd ~/.sshls查看该目录下是否之前已经生成密钥id_dsa.pub公钥文件和id_dsa私钥文件,文件名可能id_dsa可能是别的名字,但都是成对出现,其中公钥以.pub结尾。
如果没有就可以ssh-keygen来创建密钥对。该程序在 Linux/Mac 系统上由 SSH 包提供。中途需要一些额外的配置,记住输入的密码即可,其他的配置可以按enter使用默认的方式。
生成之后复制公钥id_dsa.pub的内容,在git服务器上添加SSH keys的位置添加即可。ps:cat id_dsa.pub打印公钥id_sda.pub的内容。

修改远程仓库的地址

git remote set-url <name> <newurl>name默认为origin,这样就可以将已有的https远程仓库地址修改为newurl——ssh的新地址了。