1. 程式人生 > >Github和Git的簡單使用

Github和Git的簡單使用

一、Github使用

二、Git使用(Linux下)

1.設定姓名和郵件地址

git config --global user.name "Your Name"
git config --global user.email "[email protected]"

只需替換引號內的姓名和郵件地址

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 <[email protected]> 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

如:

* fa3c141 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
     用簡短友好的格式顯示日期