git 配置多账户
- 先生成密钥对
ssh-keygen -t rsa -C 'git@test.com'
- 管理密钥,在 ~/.ssh 目录下创建 config 文件,如果没有,请创建
Host github
HostName github.com
User hello
IdentityFile ~/.ssh/id_rsa_github
Host gitlab
HostName gitlab.mygitlab.com
User world
IdentityFile ~/.ssh/id_rsa_gitlab
- Host:仓库网站的别名
- HostName:仓库网站的域名
- User: 仓库网站上的用户名
- IdentityFile : 私钥的绝对路径
1.git init 创建Git仓库
$ mkdir usb
$ cd usb
$ git init
2.git add 将文件添加仓库
$ git add sb.txt
3.git commit 将文件提交仓库
$ git commit sb.txt
4.git status 查看仓库当前状态
$ git status
5.git diff 查看difference
$ git diff
6.git reset 版本回退(在Git中,用HEAD
表示当前版本,上一个版本就是HEAD^
,上上一个版本就是HEAD^^
,当然往上100个版本写100个^
比较容易数不过来,所以写成HEAD~100
)
$ git reset --hard HEAD^
$ git reset --hard 3ba5cdb7cf87c6898279db876a9e0eb7debc8a49(commit_id)
7.git reflog 命令历史
$ git reflog
8.git checkout 让这个文件回到最近一次 git commit 或 git add 时的状态
$ git checkout -- file
9. git rm 命令 git rm
用于删除一个文件
$ git rm file