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 ...
随机推荐
- Example of ConcurrentHashMap in Java--转
原文地址:http://www.concretepage.com/java/example_concurrenthashmap_java On this page we will provide ex ...
- DEBIAN下中文显示
转:http://www.cppblog.com/colorful/archive/2012/05/28/176516.aspx 一.首先检查LOCALE情况 说明:DEBIAN因为基于GNU所以,对 ...
- ZOJ Problem Set - 1383 Binary Numbers
水题,输出的时候注意下 #include <stdio.h> #include <math.h> int main() { int d; scanf("%d" ...
- SSH整合时执行hibernate查询报错:java.lang.ClassCastException: com.ch.hibernate.Department_$$_javassist_0 cannot be cast to javassist.util.proxy
今天在整合ssh三个框架时,有一个功能,是查询所有员工信息,且员工表和部门表是多对一的映射关系,代码能正常运行到查询得到一个List集合,但在页面展示的时候,就报异常了, java.lang.Clas ...
- GeoServer中利用SLD配图之矢量图层配图
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/. 1 背景 我们在ArcMap中可以直接通过symbol功能对图层进行定 ...
- VS 2010一步步开发windows服务(windows service)
基于0起步来创建一个服务,做到简单的记录时间日志功能,其具体招行方法可自行添加. 1.创建服务 2.删除默认服务文件 3.添加自己的服务文件 4.更改启动项目 5. 引用 using System.T ...
- js构建ui的统一异常处理方案(二)
上一篇文章,我分析了同步代码做异常处理是基于责任链模式,而通过try.catch等语句可以很容易地实现这种责任链模式.但是如果是异步调用,我们无法直接通过try.catch语句实现责任链模式,并且通过 ...
- RabbitMQ原理与相关操作(二)
接着 上篇随笔 增加几个概念: RabbitMQ是一个在AMQP(高级消息队列协议)标准基础上完整的,可服用的企业消息系统. AMQP模型的功能组件图(上图摘自 Sophia_tj 的 第2章 AMQ ...
- JavaScript中的数据类型转换
本文中提到的“原始值”指的是undefined,null,Boolean,string和number. 本文中的对象是native对象,宿主对象(浏览器定义的对象)按照各自的算法转换. JavaScr ...
- Win10 UWP 开发系列:使用SQLite
在App开发过程中,肯定需要有一些数据要存储在本地,简单的配置可以序列化后存成文件,比如LocalSettings的方式,或保存在独立存储中.但如果数据多的话,还是需要本地数据库的支持.在UWP开发中 ...