Git - 安装与配置

1. 安装Gitk

安装流程可参考Git官网官方汉化教程

$ git --version
git version 2.36.1

2. 配置公钥

# 生成密钥对(可一路回车)
$ ssh-keygen -t rsa -C "Hollson@qq.com"

# 查看公约
$ cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQD3QfJ0NvIBTsLIBJ+GTJcobVHlheLEhxKnpv2H0/Z784U9JTU
R7gayTB+bHTD4Q3qCD9Y5Z8J5E6rDqHnQC/pPvWKJjc6wUvQJ8PJynRvMb1G2O2DuimL75v12cttCR775t4JkYW
bCW9XtUSuWdt6jXSq1DKDh0lzS7HQqTxh414m6+6k5peV/XPRffM0k8yBaFf8WAoaPOGXssYjLA0pnFFbbhh2+r
CnW7MjUd8LDFC5FhP9Y6JFn0WjrmOshjDKDoS/QJlZ5JAi5nHaB5kGM9YAxHM7qQ9qPyywwShwYgz+DPn+ei2Ve
B8nD+q46uiLESc9cx6aDMuYiAhzSzb8Ee5bjKtnavmfxBu6tjRhKVUNYIDKfvdG4/iqF0C91+mta4UOFB7kpp3A
MoZy5y1VLndgIJWTSd80LuH1yLURviNuUprd72H31jvHn+BCajTSXE9OHDNoILrWhynZKEhQ/pAArD0w3jF+cFT
Iym1qLWOEk8HuRy+zCPVvIgTD3dE= Hollson@qq.com

# 将公约添加到Git服务器,并验证
$ ssh -T git@github.com
Hi Hollson! You've successfully authenticated, but GitHub does not provide shell access.

3. 账号配置

3.1 通用配置

# 查看/编辑配置信息
git config --list
git config -e

# 配置全局帐号
git config --global user.name  "Hollson"
git config --global user.email "Hollson@qq.com"

# 配置项目帐号
git config user.name  "Hollson"
git config user.email "Hollson@qq.com"

cat ~/.gitconfig  # 查看全局配置文件
cat .git/config   # 查看项目配置文件

3.2 多账号配置

引用场景: 您同时拥有公司和个人两个的Github账号,如何使用两个账号操作不同的项目,而不互不干扰呢?

  • 第一步:添加账号密钥
ssh-keygen -t rsa -f ~/.ssh/id_rsa -C "hollson@gmail.com"   # 个人账号(默认)
ssh-keygen -t rsa -f ~/.ssh/work   -C "work@gmail.com"      # 工作账号
  • 第二步:修改Git全局配置

编辑vim ~/.ssh/config

# 第一个账号,即默认账号
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa  # 私钥文件名
User hollson

# 第二个账号(工作账号)
Host work.github.com  # work前缀可以任意设置
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/works # 私钥文件名
User work
  • 第三步:配置公私钥

将对应的公钥添加到不同的github账号配置中,并验证

ssh -T git@github.com
ssh -T git@work.github.com

ssh-add -D
ssh-add ~/.ssh/id_rsa   # 将「默认」私钥添加到本地
ssh-add ~/.ssh/work     # 将「工作」私钥添加到本地
ssh-add -l
  • 第四步:配置本地(工作)项目
git config user.name  "work"
git config user.email "work@gmail.com"

# 克隆或添加/修改工作项目URl
git clone git@work.github.com:xxx/program.git #注意⚠️添加work前缀
git remote set-url origin <work.URL>
git remote add origin <work.URL>

4. 个性化配置

# 配置日志格式
git config --global log.date format:'%Y-%m-%d %H:%M:%S'
git config --global blame.date format:'%Y-%m-%d %H:%M:%S'

# 配置Git别名
git config --global alias.st "status"
git config --global alias.br "branch"
git config --global alias.ci "commit"
git config --global alias.ss "stash"
git config --global alias.sg "stage"
git config --global alias.co "checkout"
git config --global alias.cp "cherry-pick"
git config --global alias.cv "cherry -v --abbrev=10"
git config --global alias.rpo "remote prune origin"
git config --global alias.rb "rebase -i"
git config --global alias.rs "reset --soft"
git config --global alias.rh "reset --hard"
git config --global alias.rl "reflog -10"
git config --global alias.ls "config -l"
git config --global alias.last 'log -1 HEAD'
git config --global alias.tree "lg --simplify-by-decoration"
git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset %C(bold blue)<%an> %Cgreen(%cr) %C(yellow)%d%Creset %C(bold magenta)%s' --abbrev-commit --date=relative"
git config --global alias.lgp "log --graph --pretty=format:'%Cred%h%Creset %Creset-> %p %C(bold blue)<%an> %Cgreen(%cr) %C(yellow)%d%Creset %C(bold magenta)%s' --abbrev-commit --date=relative"

git ls|grep alias

5. 代理服务

5.1 全局代理

# socks5协议
git config --global http.proxy socks5://127.0.0.1:1081
git config --global https.proxy socks5://127.0.0.1:1081

# http协议
git config --global http.proxy http://127.0.0.1:8000
git config --global https.proxy https://127.0.0.1:8000

git config -l

5.2 局部代理

如:仅让github走本地代理,其他的保持不变

# socks5协议
git config --global http.https://github.com.proxy socks5://127.0.0.1:1081
git config --global https.https://github.com.proxy socks5://127.0.0.1:1081

# http协议
git config --global http.https://github.com.proxy https://127.0.0.1:8000
git config --global https.https://github.com.proxy https://127.0.0.1:8000

5.3 取消代理

git config --global --unset http.proxy
git config --global --unset https.proxy
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
git-svn 是一个桥接工具,用于在 Git 和 Subversion (SVN) 之间进行转换和交互。下面是 git-svn 的安装配置过程。 安装 Git: 1. 在官网 (https://git-scm.com/downloads) 上下载适合你操作系统的 Git 安装程序。 2. 打开安装程序并按照指示进行安装。 3. 验证安装是否成功,在命令提示符或终端上运行 "git --version" 命令,如果出现 Git 的版本号信息,则说明安装成功。 配置 Git: 1. 打开命令提示符或终端,并运行以下命令来配置你的 Git 用户名和邮箱: ``` git config --global user.name "你的用户名" git config --global user.email "你的邮箱地址" ``` 安装 Git-svn 桥接工具: 1. 在命令提示符或终端上运行以下命令安装 Git-svn: - 在 Ubuntu 上使用 apt-get: ``` sudo apt-get install git-svn ``` - 在 macOS 上使用 Homebrew: ``` brew install git-svn ``` - 在 Windows 上使用 Scoop: ``` scoop install git-svn ``` 配置 Git-svn: 1. 在命令提示符或终端上运行以下命令配置 Git-svn: ``` git svn init [SVN 仓库 URL] -s ``` 2. 这将为你的 Git 仓库创建一个指向 SVN 仓库的远程“refs/remotes/origin/trunk”引用。 3. 运行以下命令来下载远程 SVN 仓库的历史记录: ``` git svn fetch ``` 4. 这将下载远程 SVN 仓库的历史记录到你的本地 Git 仓库。 5. 当你想要提交更改时,使用 Git 的命令,例如 "git add"、"git commit"等来管理更改,并使用以下命令将更改推送到 SVN 仓库: ``` git svn dcommit ``` 以上是 git-svn 的安装配置过程。-git提供了更快速、灵活、分布式的版本控制系统,而git-svn桥接工具则使得想要在 git 和 Subversion (SVN)之间进行转换和交互的用户能够灵活使用两种工具。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值