讀GitNotesForProfessionals記錄

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

http://gitforwindows.org/

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"

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • git作為時下最流行的代碼管理工具,Git權(quán)威指南總結(jié)了十條喜歡Git的理由: 異地協(xié)同工作; 現(xiàn)場版本控制; 重...
    古斟布衣閱讀 1,847評論 0 12
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 134,881評論 18 139
  • git常用命令 GIT常用命令備忘:http://stormzhang.com/git/2014/01/27/gi...
    新篇章閱讀 8,583評論 1 26
  • 丙申二月初五,又逢一季花開,游武大櫻園,有感,作此詩,以記之。 人間二月春寒去,武大櫻花竟相開。 落英繽紛仙女舞...
    E世繁華閱讀 168評論 1 1
  • 是有真跡,如不可知。意象欲出,造化已奇。水流花開,清露未晞。要路愈遠,幽行為遲。語不欲犯,思不欲癡。猶春于綠...
    秋水長天碧閱讀 349評論 2 1