git基础入门

来源:互联网 发布:cx域名不值钱吗 编辑:程序博客网 时间:2024/06/18 11:42

git基础入门

创建初始版本库(目录转换成git版本库)

cd /gitgit --version创建初始版本库(目录转换成git版本库)git initvim index.html

添加到版本库,git只是暂存/staged文件

git add index.html更新版本库 git commit index.html -m 'add index.html'文件被add一次后再次修改可以直接commit,无需再次add

查看提交

git loggit show commitID查看简洁单行摘要,前10个版本git show-branch --more=10

查看提交差异

git diff ID ID删除git rm index.htmlgit commit -m 'delete index.html'移动git mv index.html test.htmlgit 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=onelinegit 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 rsa1、 登录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