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.提交已经add的文件 git commit -m "commit message"
7.添加远程 git remote
两个参数 1.远程分支名称 2.远程url
git remote add origin https://<your-git-service-address>/owner/repository.git
Section 1.2 Clone a repository
1.创建一个文件夹 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
两种方式没什么区别,但是GitHub建议使用https
Section 1.3: Sharing code
在远程服务器上 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 )参数指定追踪关系
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
单个仓库配置优先于全局配置
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
参数解释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
查看提交数git shortlog -s
Section 2.7: Searching commit string in git log
搜索commit git log [options] --grep "search_string"
网友评论