读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.提交已经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

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

参数解释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"

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • git作为时下最流行的代码管理工具,Git权威指南总结了十条喜欢Git的理由: 异地协同工作; 现场版本控制; 重...
    古斟布衣阅读 1,905评论 0 12
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,680评论 19 139
  • git常用命令 GIT常用命令备忘:http://stormzhang.com/git/2014/01/27/gi...
    新篇章阅读 8,887评论 1 26
  • 丙申二月初五,又逢一季花开,游武大樱园,有感,作此诗,以记之。 人间二月春寒去,武大樱花竟相开。 落英缤纷仙女舞...
    E世繁华阅读 196评论 1 1
  • 是有真迹,如不可知。意象欲出,造化已奇。水流花开,清露未晞。要路愈远,幽行为迟。语不欲犯,思不欲痴。犹春于绿...
    秋水长天碧阅读 403评论 2 1

友情链接更多精彩内容