Chapter 1: Getting started with Git
Section 1.1
1.安裝git 配置姓名郵箱
2.查看版本 git --version
3.在需要版本控制文件目錄下初始化一個空的git倉庫 git init
4.添加需要控制的文件 git add <file/directory name>
或者添加目錄下所有文件 git add .
5.如果不需要版本控制的文件,在.git同級目錄添加.gitignore文件,寫入不需要控制的文件名
6.提交已經(jīng)add的文件 git commit -m "commit message"
7.添加遠程 git remote
兩個參數(shù) 1.遠程分支名稱 2.遠程url
git remote add origin https://<your-git-service-address>/owner/repository.git
Section 1.2 Clone a repository
1.創(chuàng)建一個文件夾 git clone https://github.com/username/projectname.git
當前文件夾包含clone下來的項目
也可以指定clone下來projectname
git clone https://github.com/username/projectname.git MyFolder
或者直接clone到當前目錄不需要projectname
git clone https://github.com/username/projectname.git .
注:1.指定directory時,directory必須為空或者不存在
2.ssh方式也可 git clone git@github.com:username/projectname.git
兩種方式?jīng)]什么區(qū)別,但是GitHub建議使用https
Section 1.3: Sharing code
在遠程服務(wù)器上 git init --bare /path/to/repo.git
bare裸倉庫,不包含working copy。和其他人更容易共享更新
在本地 git remote add origin ssh://username@server:/path/to/repo.git
把本地的倉庫推送到遠程 git push --set-upstream origin master
--set-upstream (or -u )參數(shù)指定追蹤關(guān)系
Section 1.4: Setting your user name and email
1.對所有倉庫配置身份
git config --global user.name "Your Name"
git config --global user.email mail@example.com
2.對單個倉庫配置身份
cd /path/to/my/repo
git config user.name "Your Login At Work"
git config user.email mail_at_work@example.com
單個倉庫配置優(yōu)先于全局配置
3.移除全局身份
git config --global --remove-section user.name
git config --global --remove-section user.email
4.Version ≥ 2.8可在指定倉庫強制忽略身份
git config --global user.useConfigOnly true
配置完后提交會報錯誤——>沒有用戶名和郵箱
Section 1.5: Setting up the upstream remote
暫時不寫
Section 1.6: Learning about a command
通過 git diff --help或者git help diff查看doc
或者command查看命令簡介
git checkout -h
Section 1.7: Set up SSH for Git
查看 ~/.ssh目錄 ls ~/.ssh
id_rsa id_rsa.pub known_hosts
沒得的話生成一個 ssh-keygen
Section 1.8: Git Installation
Chapter 2: Browsing the history
Section 2.1: "Regular" Git Log
查看最近兩次提交 git log -2
Section 2.2: Prettier log
圖形展示 git log --decorate --oneline --graph
太長了配置別名
git config --global alias.lol "log --decorate --oneline --graph"
Section 2.3: Colorize Logs
參數(shù)解釋git log help
git log --graph --pretty=format:'%C(red)%h%Creset -%C(yellow)%d%Creset %s %C(green)(%cr)%C(yellow)<%an>%Creset'
Section 2.4: Oneline log
簡介log一行展示
git log --oneline
也可使用git log -2 --oneline
Section 2.5: Log search
字符git log -S"#define SAMPLES"
正則git log -G"#define SAMPLES"
Section 2.6: List all contributions grouped by author name
查看每個人的提交歷史
git shortlog
查看提交數(shù)git shortlog -s
Section 2.7: Searching commit string in git log
搜索commit git log [options] --grep "search_string"