git 基操

ssh key 多用户配置

删除全局用户信息

多用户情况下,尽量不要设置全局用户信息

# 添加全局用户信息
git config --global user.name "用户名"
git config --global user.email "邮箱"
#删除全局用户信息
git config --global --unset user.name
git config --global --unset user.email

生成 key

$ ssh-keygen -t rsa -C "github@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): id_rsa_github
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in id_rsa_github.
Your public key has been saved in id_rsa_github.pub.
The key fingerprint is:
SHA256:K8ZzHA4rrhgHlv7qyP+dAmvpQIq+jPUpbMdjXZncAnE github@qq.com
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|      . E        |
|       o         |
|  .   .          |
|.+    .oS+       |
|*. . . =*o.      |
|++o.=.*.=.       |
|*=**==o+.        |
|=OBO=o.o         |
+----[SHA256]-----+

将 key 添加至相应的网站

配置 config

文件位置 ~/.ssh/config 注意:不可有注释

Host github.com
    User github
    Hostname github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa_github
Host 192.168.12.5
    User gitlab
    Hostname 192.168.12.5
    Port 122 # 如果不是22则添加次行
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa_gitlab

将密码加入密匙管理器

$ ssh-agent bash
$ ssh-add ~/.ssh/id_rsa_github
Enter passphrase for /c/Users/Administrator/.ssh/id_rsa_github:
Identity added: /c/Users/Administrator/.ssh/id_rsa_github (/c/Users/Administrator/.ssh/id_rsa_github)
 
$ ssh-add ~/.ssh/id_rsa_gitlab
Enter passphrase for /c/Users/Administrator/.ssh/id_rsa_gitlab:

使用细节

  1. clone 项目时, 最好使用 ssh 而不是 https
  2. 由于删除了全局用户配置信息,所以每次 clone 之后都需要配置当前项目的用户名与邮箱
git config user.name "xxx"
git config user.emial "xxx"

使用 beyond compare 比较代码

参考

Ubuntu Git配置Beyond Compare为比较工具

配置

[diff]
	tool = bc4
[difftool]
	prompt = false
[difftool "bc4"]
	cmd = /usr/bin/bcompare \"$LOCAL\" \"$REMOTE\"
[merge]
	tool = bc4
[mergetool]
	prompt = false
[mergetool "bc4"]
	cmd = /usr/bin/bcompare \"$LOCAL\" \"$REMOTE\" \"-savetarget=$MERGED\"
	trustexitcode = true
[alias]
	d = difftool
	m = mergetool
	dd = difftool --dir-diff --no-symlinks
laolang@laolang-pc:~$ cat .gitconfig 
[diff]
	tool = bc4
[difftool]
	prompt = false
[difftool "bc4"]
	cmd = /usr/bin/bcompare \"$LOCAL\" \"$REMOTE\"
[merge]
	tool = bc4
[mergetool]
	prompt = false
[mergetool "bc4"]
	cmd = /usr/bin/bcompare \"$LOCAL\" \"$REMOTE\" \"-savetarget=$MERGED\"
	trustexitcode = true
[alias]
	d = difftool
	dc = difftool --cached
	m = mergetool
	dd = difftool --dir-diff --no-symlinks
	ddc = difftool --dir-diff --no-symlinks --cached

使用说明

  1. git d 文件名 : 比较某个文件
  2. git dc 文件名 : 比较某个文件 (已暂存的)
  3. git dd : 比较文件夹
  4. git ddc : 比较文件夹 (已暂存的)

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值