一、Github使用
具体参考Tutorial: https://guides.github.com/activities/hello-world/
二、Git使用(Linux下)
1.设置姓名和邮件地址
git config --global user.name "Your Name"
git config --global user.email "your_email@whatever.com"
只需替换引号内的姓名和邮件地址
2.创建项目
2.1 创建"Hello, World"页面
mkdir hello
cd hello
touch hello.html
2.2 创建repository
git init
2.3 将页面添加到repository
git add hello.html
git commit -m "First Commit"
3. 检查repository的status
git status
4. 检查历史
命令:git log,结果如下:
Author: wxb2dyj <wxb2dyj@gmail.com>
Date: Thu Oct 11 16:35:09 2018 +0800
First Commit
或每行一条
命令:git log --pretty=oneline,结果如下:
639a9d902a222b56a6e49b9468b47da847c31ea6 First Commit
或自定义显示
git log --pretty=oneline --max-count=2 //最大显示条数
git log --pretty=oneline --since='5 minutes ago' //筛选5分钟前开始到现在的提交
git log --pretty=oneline --until='5 minutes ago' //筛选项目开始到5分钟前截止的提交
git log --pretty=oneline --author=<your name> //根据提交者来筛选
git log --pretty=oneline --all //显示所以提交信息
常用格式
git log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short
如:
* 639a9d9 2018-10-11 | First Commit (HEAD -> master) [your name]
说明:
--pretty="..."
defines the output format.%h
某次提交生成的哈希码%d
标签 (e.g. branch heads or tags)%ad
日期%s
描述%an
提交者姓名--graph
指定用ASCII图层格式来显示提交树--date=short
用简短友好的格式显示日期
5. 命令简化
常用的git命令比较长,可以进行简化。修改$HOME下的.gitconfig文件,添加以下内容:
[alias]
co = checkout
ci = commit
st = status
br = branch
hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
type = cat-file -t
dump = cat-file -p
6. 从Git到Github
用git commit本地提交项目后,可以通过下面命令将项目下的文件上传到Github:
git remote add origin https://github.com/user_name/repository_name.git
git push -u origin master //将本地主分支推到远程(如无远程主分支则创建,用于初始化远程仓库)
###
此时如果出现"error: failed to push some refs to",则输入以下命令:
git pull origin master //把远程库更改拉到本地仓库
然后再执行git push -u origin master
###
git push origin master //将本地主分支推到远程主分支
此时可以在Github中的仓库repository_name中找到上传的文件。