git基础入门
创建初始版本库(目录转换成git版本库)
cd /git
git --version
创建初始版本库(目录转换成git版本库)
git init
vim index.html
添加到版本库,git只是暂存/staged文件
git add index.html
更新版本库
git commit index.html -m 'add index.html'
文件被add一次后再次修改可以直接commit,无需再次add
查看提交
git log
git show commitID
查看简洁单行摘要,前10个版本
git show-branch --more=10
查看提交差异
git diff ID ID
删除
git rm index.html
git commit -m 'delete index.html'
移动
git mv index.html test.html
git commit -m 'mv index.html test.html'
配置文件
(1).git/config
版本库特定的配置,针对一个git版本即一个目录。优先级最高
git config [--file] user.name 'hannah.jiang'
(2)~/.gitconfig
用户特定的配置设置,可用--global修改
git config --global user.name 'hannah.jiang'
(3)/etc/gitconfig
系统范围的配置。用--system选项修改
查看所有配置
git config -l
移除设置
git config --unset --global user.name
配置别名
git log --graph --abbrev-commit --pretty=oneline
git config --global alias.show-graph \
'log --graph --abbrev-commit --pretty=oneline'
git show-graph
查看配置文件
$ cat .git/config
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[user]
email = 123@163.com
name = hannah
[alias]
show-graph = log --graph --abbrev-commit --pretty=oneline
github的ssh配置
检查本机是否有ssh key设置
$ cd ~/.ssh
$ ssh-keygen -t rsa
1、 登录GitHub系统;点击右上角账号头像的“▼”→Settings→SSH kyes→Add SSH key。
2、进入cd ~/.ssh/目录下,打开id_rsa.pub文件,全选复制公钥内容。
3、将公钥粘贴到GitHub中Add an SSH key的key输入框,保存
测试ssh keys是否设置成功。
$ ssh -T git@github.com