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的更多相关文章

  1. Deep Learning Papers Reading Roadmap

    Deep Learning Papers Reading Roadmap https://github.com/songrotek/Deep-Learning-Papers-Reading-Roadm ...

  2. 【Paper Reading】Learning while Reading

    Learning while Reading 不限于具体的书,只限于知识的宽度 这个系列集合了一周所学所看的精华,它们往往来自不只一本书 我们之所以将自然界分类,组织成各种概念,并按其分类,主要是因为 ...

  3. GIT Learning

    一.Why Git 1.1 Git是分布式的,本地的版本管理 chect out代码后会在自己的机器上克隆一个自己的版本库,即使你在没有网络的环境,你仍然能够提交文件,查看历史版本记录,创建项目分支, ...

  4. Git Learning Part III - working remotely (Github)

    help document of Github : https://help.github.com/ 1 upload 1.1 new update  Initialize a repository  ...

  5. Git Learning Part II - Working locally

    file status life circle basic: modified:   Examples: untracked: unmodified: modified: Git branching ...

  6. 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 ...

  7. mathematics of deep learning (paper reading)

    1.数学上,不变性 2.信息论上

  8. Git的Patch功能

    转自:http://www.cnblogs.com/y041039/articles/2411600.html UNIX世界的软件开发大多都是协作式的,因此,Patch(补丁)是一个相当重要的东西,因 ...

  9. Difference between git pull and git pull --rebase

    个人博客地址:  http://www.iwangzheng.com/ 推荐一本非常好的书 :<Pro Git>  http://iissnan.com/progit/ 构造干净的 Git ...

随机推荐

  1. UWP开发之Mvvmlight实践四:{x:bind}和{Binding}区别详解

    {x:bind}是随着UWP被推出而被添加的,可以说是Win10 UWP开发专有扩展.虽然 {x:Bind} 缺少{Binding} 中的一些功能,但它运行时所花费的时间和使用的内存量均比 {Bind ...

  2. 编写简单的ramdisk(有请求队列)

    前言 前面用无请求队列实现的ramdisk的驱动程序虽然申请了请求队列,但实际上没用上,因为ramdisk不像实际的磁盘访问速度慢需要缓存,ramdisk之间使用内存空间,所以就没用请求队列了.本文将 ...

  3. Java内存模型深度解析:final--转

    原文地址:http://www.codeceo.com/article/java-memory-6.html 与前面介绍的锁和Volatile相比较,对final域的读和写更像是普通的变量访问.对于f ...

  4. 附录E 安装Kafka

    E.1   安装Kafka E.1.1    下载Kafka Kafka是由LinkedIn设计的一个高吞吐量.分布式.基于发布订阅模式的消息系统,使用Scala编写,它以可水平扩展.可靠性.异步通信 ...

  5. 自己动手丰衣足食之 jQuery 数量加减插件

    引言 做一个手机端的订单相关项目中,其中下订单时需要用到数量加减的控件,可以设置默认值,也可以设置最大值和最小值.使用jQuery这么长时间了,平时很少去编写属于自己的插件,现在编写的时候对立面的一些 ...

  6. Android 源码下载方法(Git 方式clone)

    Android源码对于Android开发者来说,迟早有一天你会用到的,所以就记录一下,分享给读者,希望对读者有用 这里需要使用到Git相关知识,不清楚的可以先阅读,了解的可以跳过 Git-Tortoi ...

  7. jQuery-1.9.1源码分析系列(十五) 动画处理——外篇

    a.动画兼容Tween.propHooks Tween.propHooks提供特殊情况下设置.获取css特征值的方法,结构如下 Tween.propHooks = { _default: { get: ...

  8. 使用、支持、帮助Moon.Orm

    1.关于Moon.Orm的说明 1)任何人和组织都可以免费使用该框架;(赞助者提供长期的技术咨询)  微信微信: 2)5.0之前已经全部开源; 3)5.0标准版本目前对参与者开源(看看下面很简单的), ...

  9. JS围棋半成品

    // = 0 && cheseArray[x][y-1] == chessState.None){ return true; } if(y + 1 = 0 &&ches ...

  10. entity framework 删除数据库出现错误的解决方法--最土但是很有效的方法

    无法删除数据库,因为该数据库当前正在使用. public ChinaerContext() : base("name=ContextConn") { // Database.Set ...