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. iPhone 6/plus iOS Safari fieldset border 边框消失

    问题:iPhone6 plus 手机浏览网页,fieldset border 边框消失. 示例代码: <div> <fieldset style="border: 1px ...

  2. php上传功能集后缀名判断和随机命名

    form.php <html> <head> <meta http-equiv="content-type" content="text/h ...

  3. 触屏touch事件记录

    一.chrome中的Remote Debugging 一开始并没有用这个调试,不过后面需要多点触碰,可chrome模拟器中我没看到这个功能.突然看到了Remote Debugging,网站需要FQ才能 ...

  4. 回忆:#define的用法

    ANSI C规定:#前可以有空格或者tab,#和指令其余部分之间也可以有空格,可以出现在任何地方,作用域从定义处到文件结尾. 因为预处理开始前,系统会删除反斜线和换行符的组合,故可以把指令扩展到几个物 ...

  5. IntelliJ IDEA上创建maven Spring MVC项目

    IntelliJ IDEA上创建Maven Spring MVC项目 各软件版本 利用maven骨架建立一个webapp 建立相应的目录 配置Maven和SpringMVC 配置Maven的pom.x ...

  6. ZOJ Problem Set - 1067 Color Me Less

    这道题目很简单,考察的就是结构体数组的应用,直接贴代码了 #include <stdio.h> #include <math.h> typedef struct color { ...

  7. Android Conflict with nineoldandroids等报错

    问题 报错:Conflict with nineoldandroids 原因 我在引入Fresco时由于其中也包含nineoldandroids这个库,导致库的冲突,相关的库冲突都是因为这个问题导致的 ...

  8. Bootstrap3 Grid system原理及应用

    刚开始用Bootstrap的格子系统写布局的时候遇到了这样一个问题: 我的页面中有这样一个布局 我希望当屏幕的宽度小于他们俩宽度之和的时候,右边的部分会掉下来,他们垂直摆放. 而我用col-xs-6的 ...

  9. Html 文档在线编辑器

    // //

  10. Matches正则使用提取内容

    用VS新建WinForm程序,窗体上是三个文本框和一个按钮.可以自己构造正则表达式,自己修改匹配内容 正则表达是要提取的部分为hewenqitext 代码如下: using System; using ...