Git Learning - By reading ProGit
Today I begin to learn to use Git.
I learn from Pro Git. And I recommend it which is an excellent book.
Some Ideas:
Git is a Distributed Version Control System and it is brilliant.
And we know that DDoS attack is famous and distributed as well.
So, distributed things may be very wonderful.
Notes:
- Git regard the whole directory as a filesystem and create snapshots for it, not for single file
- Files in the respository may be in one of four types: untracked, tracked:modified, tracked:staged, tracked:committed
- Git uses SHA-1 Hash Algorithm
- .git is the most important part of Git, and it is what is copied when you clone a repository from another computer


# Configure
git config --global user.name "brant-ruan"
git config --global user.email xxxx@xx.xx
git config --global core.editor vim # specify editor
git config --list # show your configurations
# Init
# Go into a new directory which you will use as a respository
git init # create a .git directory
# Then I write a helloworld program named "hello.c"
# And I write a plain text README
# Each file in your working directory can be in one of two states: tracked or untracked.
# Tracked files were in the last snapshot(they can be unmodified, modified, or staged)
git add *.c
git add README
git commit -m 'initial project version'
# Clone
git clone URL [optional: your directory name]
# GIt has many transfer protocols you can use
# Check Status
git status # check status of your files
# Git stages a file as it is when you run the [git add] command.
# now I add a new sentence in README and stage it:
git add README
# Ignore files
# you may have a class of files that you don't want Git to automatically add or show you as beingg untracked.
# and you can create a file listing patterns to match them named .gitignore:
vim .gitignore
*.[oa]
*~
!lib.a # means that lib.a will be showed and not ignored
#View Your Staged and Unstaged Changes
git diff
git diff --staged
# git diff --cached to see what you've staged so far.
# Commit
git commit -m "commit message"
# it will output:
[master 9932eed] second commit
1 file changed, 4 insertions(+)
# the 9932eed is the result SHA-1 checksuming the commit
git commit -a -m 'message'
# Git automatically stage every file that is already tracked, and you can skip git add
# Remove files
git rm filename
# then commit
git rm --cached README# just rm it from your staging area (still on your disk)
# Rename a file in git repository
git mv file_src file_dst
# View the commit history
git log
git log -p # show difference introduce in each commit
git log --stat # show modified files
# Undo things
# Undo commit
git commit --amend [-m 'string']
# This command takes your staging area and uses it for the commit
# Unstage a staged file
git reset HEAD filename
# Unmodify a modified file
git checkout -- filename # Attention ! That may be dangerous !
# Work with Remotes
cd respository-path # you have cloned a respository here before
git remote # to see which remote servers you have configured
git remote -v # show URLs to be used when reading and writing to that remote
git remote add [shortname] [url] # add remote repositories
e.g.
git remote add pb https://github.com/paulboone/ticgit
# fetch
git fetch pb
# If you clone a repository, the command automatically adds that remote
# repository under the name “origin”. So, git fetch origin fetches any new
# work that has been pushed to that server since you cloned (or last fetched
# from) it.
# git fetch command pulls the data to
# your local repository – it doesn’t automatically merge it with any of your work
# or modify what you’re currently working on. You have to merge it manually into
# your work when you’re ready.
# git clone command automatically sets up your local master branch to
# track the remote master branch (or whatever the default branch is called) on
# the server you cloned from
# push to remotes
git push [remote-name] [branch-name]
e.g.
git push origin master
# inspect a remote
git remote show [remote-name]
# remove and rename remotes
git remote rename [old-shortname] [new-shortname]
git remote rm [short-name]
# Tag
git tag # list tag
# create tag
# Git uses two main types of tags: lightweight and annotated.
# A lightweight tag is very much like a branch that doesn’t change – it’s just a
# pointer to a specific commit.
# Annotated tags, however, are stored as full objects in the Git database.
# They’re checksummed; contain the tagger name, e-mail, and date; have a tag-
# ging message; and can be signed and verified with GNU Privacy Guard (GPG).
# It’s generally recommended that you create annotated tags so you can have all
# this information; but if you want a temporary tag or for some reason don’t want
# to keep the other information, lightweight tags are available too.
git tag -a v1.4 -m 'my version' # annotated tags
git show v1.4
git tag v1.4-lw # lightweight tags
# share tag:
git push origin [tagname]
Git Learning - By reading ProGit的更多相关文章
- Deep Learning Papers Reading Roadmap
Deep Learning Papers Reading Roadmap https://github.com/songrotek/Deep-Learning-Papers-Reading-Roadm ...
- 【Paper Reading】Learning while Reading
Learning while Reading 不限于具体的书,只限于知识的宽度 这个系列集合了一周所学所看的精华,它们往往来自不只一本书 我们之所以将自然界分类,组织成各种概念,并按其分类,主要是因为 ...
- GIT Learning
一.Why Git 1.1 Git是分布式的,本地的版本管理 chect out代码后会在自己的机器上克隆一个自己的版本库,即使你在没有网络的环境,你仍然能够提交文件,查看历史版本记录,创建项目分支, ...
- Git Learning Part III - working remotely (Github)
help document of Github : https://help.github.com/ 1 upload 1.1 new update Initialize a repository ...
- Git Learning Part II - Working locally
file status life circle basic: modified: Examples: untracked: unmodified: modified: Git branching ...
- Git Learning Part I - Install Git and configure it
Why we need 'Git' GIt version control: 1. record the history about updating code and deleting code 2 ...
- mathematics of deep learning (paper reading)
1.数学上,不变性 2.信息论上
- Git的Patch功能
转自:http://www.cnblogs.com/y041039/articles/2411600.html UNIX世界的软件开发大多都是协作式的,因此,Patch(补丁)是一个相当重要的东西,因 ...
- Difference between git pull and git pull --rebase
个人博客地址: http://www.iwangzheng.com/ 推荐一本非常好的书 :<Pro Git> http://iissnan.com/progit/ 构造干净的 Git ...
随机推荐
- 如何搭建Percona XtraDB Cluster集群
一.环境准备 主机IP 主机名 操作系统版本 PXC 192.168.244.146 node1 ...
- 项目中遇到的Integer问题--转
Integer类型值相等或不等分析 http://www.cnblogs.com/zzllx/p/5778470.html 看到博客园一位博友写的面试问题,其中一题是 Integer a = 1; I ...
- 浅析JS中的模块规范(CommonJS,AMD,CMD)
如果你听过js模块化这个东西,那么你就应该听过或CommonJS或AMD甚至是CMD这些规范咯,我也听过,但之前也真的是听听而已. 现在就看看吧,这些规范到底是啥东西,干嘛的. 一.CommonJS ...
- (转载)构建public APIs与CORS
from: https://segmentfault.com/a/1190000000709909 理由:在操作层面详细的讲解了跨域的操作.尤其是对于option请求的详解.收藏. 在构建Public ...
- 谈谈JAVA工程狮面试中经常遇到的面试题目------什么是MVC设计模式
作为一名java工程狮,大家肯定经历过很多面试,但每次几乎都会被问到什么是MVC设计模式,你是怎么理解MVC的类似这样的一系列关于MVC的问题. [出现频率] [关键考点] MVC的含义 MVC的结构 ...
- 【Kylin实战】邮件报表生成
在cube build完成后,我的工作是写sql生成数据分析邮件报表.但是,问题是这种重复劳动效率低.易出错.浪费时间.还好Kylin提供RESTful API,可以将这种数据分析需求转换成HTTP请 ...
- 对于SQL Server,我需要多少内存
经常被问到的一个问题:对于SQL Server,我需要多少内存?这个问题还是有同样的典型的“看情况而定”答案.在今天的文章里,我们来详细看下“看情况而定的”的不同方面. 全新SQL Server安装 ...
- MySQL5.7不停业务将传统复制变更为GTID复制
由于GTID的优势,我们需要将传统基于file-pos的复制更改为基于GTID的复制,如何在线变更成为我们关心的一个点,如下为具体的方法: 目前我们有一个传统复制下的M-S结构: port 330 ...
- 从零开始,搭建博客系统MVC5+EF6搭建框架(4)上,前后台页面布局页面实现,介绍使用的UI框架以及JS组件
一.博客系统进度回顾以及页面设计 1.1页面设计说明 紧接前面基础基本完成了框架搭建,现在开始设计页面,前台页面设计我是模仿我博客园的风格来设计的,后台是常规的左右布局风格. 1.2前台页面风格 主页 ...
- jQuery on()方法
jQuery on()方法是官方推荐的绑定事件的一个方法. $(selector).on(event,childSelector,data,function,map) 由此扩展开来的几个以前常见的方法 ...