安装
下载
安装
- 注意下安装的路径即可
常用操作
配置ssh
首次使用先设置用户名和邮箱
1
2git config --global user.email "****@**.com"
git config --global user.name "xxxx"查看是否已经存在密钥(如果存在但是不想用可以删除rm -rf)
1
2cd ~/.ssh
ls生成密匙(连按三个回车)
1
ssh-keygen -t rsa -C "*****@**.com"
在C:\Users\Administrator\.ssh目录下就生成好了
将公匙配置在对应的账户中即可。
克隆仓库和初始化仓库
1
2git clone [url]
git init [project-name]其他常用操作
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36add
添加当前目录所有文件
git add .
#添加制定目录包括子目录
git add [dir]
commit
git commit -a -m [message]
branch
显示所有分支
git branch -a
新建分支
git branch [branch-name]
切换分支
git checkout [branche-name]
tag
查看所有tag
git tag
新建一个tag
git tag [tag]
提交所有的tag
git push [remote] --tags
查看
git log
remote
退送到远程分支
git push [remote] [branch]
git push [remote] [branch] --force
拉取远程分支
git pull [remote] [branch]
更新本地仓库
git fetch
回滚
本地回滚
git reset --hard [commit]
本地远程回滚
git revert [commit]
进阶操作
多ssh账户配置
创建多个公私匙对。用于不用账户验证。
将对应公匙部署到对应的服务上
在~/.ssh/目录系下创建config文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15# user1
Host codehub.devcloud.huaweicloud.com //决定你git@xxx的xxx部分,包括克隆链接部分也要进行修改
HostName codehub.devcloud.huaweicloud.com //服务的域名
User cwx618143 //你想要显示的用户名
IdentityFile ~/.ssh/id_rsa_application_1 //该服务对应的私匙
# user2
Host wlcb
HostName codehub.devcloud.huaweicloud.com
User cwx618143
IdentityFile ~/.ssh/id_rsa_application_2
# user3
Host github.com
HostName github.com
User dncba
IdentityFile ~/.ssh/id_rsa_application_3测试连通性
1
ssh -T git@Host //Host为你配置的host