git基礎入門

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 = [email protected]
    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 [email protected]
發佈了32 篇原創文章 · 獲贊 13 · 訪問量 15萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章