Pro Git学习笔记(二)—Git 基础

    http://blog.vars.me/blog/2013/07/23/pro-gitxue-xi-bi-ji-er-git-ji-chu/

    学习网址

    http://www.liaoxuefeng.com/wiki


    两种取得 Git 项目仓库的方法:
    1.从当前目录初始化:

    #首先切换到你的项目的根目录
    $ git init

    初始化后,在当前目录下会出现一个名为 .git 的目录,所有 Git 需要的数据和资源都存放在这个目录中。不过目前,仅仅是按照既有的结构框架初始化好了里边所有的文件和目录,但我们还没有开始跟踪管理项目中的任何一个文件。
    如果当前目录下有几个文件想要纳入版本控制,需要先用 git add 命令告诉 Git 开始对这些文件进行跟踪,然后提交:

    $ git add *.c
    $ git add README
    $ git commit -m ‘initial project version’
    现在,你已经得到了一个实际维护着若干文件的 Git 仓库。
    2.从已有仓库克隆
    使用 clone 而不是 checkout。这是个非常重要的差别。Git 收取的是项目历史的所有数据(每一个文件的每一个版本),服务器上有的数据克隆之后本地也都有了。实际上,即便服务器的磁盘发生故障,用任何一个克隆出来的客户端都可以重建服务器上的仓库,回到当初克隆时的状态(可能会丢失某些服务器端的挂钩设置,但所有版本的数据仍旧还在,有关细节请参考第四章)


    #clone命令格式:
    git clone [url] [new_name]
    #例如:克隆 Ruby 语言的 Git 代码仓库 Grit
    $ git clone git://github.com/schacon/grit.git
    #在clone时重新制定要新建项目的名称
    $ git clone git://github.com/schacon/grit.git mygrit
    Git 支持许多数据传输协议。上面的例子使用的是 git:// 协议,不过你也可以用 http(s):// 或者user@server:/path.git 表示的 SSH 传输协议,有关细节请参考第四章。


    获取帮助
    想了解 Git 的各式工具该怎么用,可以阅读它们的使用帮助,方法有三:

    $ git help
    $ git —help
    $ man git-
    比如,要学习 config 命令可以怎么用,运行:

    $ git help config
    我们随时都可以浏览这些帮助信息而无需连网。 不过,要是你觉得还不够,可以到 Freenode IRC 服务器(irc.freenode.net)上的 #git 或 #github 频道寻求他人帮助。这两个频道上总有着上百号人,大多都有着丰富的 Git 知识,并且乐于助人。


    Git基础命令
    it config —system windows
    config level
    System : /etc/gitconfig
    Global : ~/.gitconfig

    local : .git/config
    git config user.name “yaownqiang” default icon fig level is locally
    git config —global user.name ‘yaowenqiang’ config level globally
    git config —global user.email yaowenqiang111@163.com
    git config user.email read the user.email config value
    git config —global color.ui true
    git init
    git add . //add current folder
    git commit -a Tell the command to automatically stage files that have been modified and
    deleted, but new files you have not told git about are not affected.
    git commit -m ‘message content’ add message to the commit without opening a editor
    git commit -am ‘message’
    git cat-file -p 91992be65ef15ea6a80f42687e2a5eb489386681
    git diff README
    git diff —staged README
    git diff —cached README
    git diff HEAD README
    git log
    git log —stat
    git log —oneline
    git diff a1d865a README
    git diff a1d865a TODO

    git log —graph
    git log —oneline —graph
    git log —pretty=”%h,%cn,%cr”
    http://git-scm.com/docs/git-log

    %H - commit Hash
    %ad — Author Date
    %h — Abbreviated Commit hash
    %ar — Authro Date,Relative
    %T — Tree Hash
    %cn — Committer Name
    %t — Abbreviated Tree Hash
    %ce — Committer Email
    %P — Parent Hashes
    %cd — Committer Date
    %cr — Committer Date,relative
    %p — Abbreviated Parent Hashes
    %an — Author Name
    %s — Subject (Commit Message)
    %ae — Author E-mail
    gitk
    git branch
    git branch experimental-1 //create a branch
    git checkout experimental-1 //switch to a branch
    git checkout -b bug-fix-1 //create and switch to a new branch called bug-fix-1 if branch bog-fix-1 does not exist.
    git log —oneline —graph —all //view all branch logs
    git log —oneline —graph —all —decorate //view all branch logs and branch name
    gitk —all
    alias gl=”git log —all —graph —oneline —decorate”
    git merge bug-fix-1
    git branch -d bug-fix-1 //delete a branch
    git rebase experimental-1
    ssh-keygen -t rsa -C ‘yaowenqiang111@163.com’
    ssh -T git@github.com
    ssh-agent
    git push -u origin master
    git remote add
    git remote
    git branch -a //show all branches
    git mv README README.markdown
    git pull
    git fetch
    git checkout —orphan gh-pages
    git add -i //interactive add
    Update>> -2 //-2 means discard update 2
    git add -p //shortcut for patch
    git stash
    git stash list
    git stash save ‘stash comment’
    git stash apply
    git stash apply stash(1)
    git stash pop
    git stash drop
    git alias
    git config —global alias.s status
    git config —global alias.a add
    git config —global alias.co checkout
    git config —global alias.cm commit
    //alias in .bash_aliases
    alias ga=’git add’ alias gst=’git status’
    alias gco=’git checkout’
    alias gc=’git commit’
    alias gi=’git add -i’
    alias gaa=’git add .’

    customize the prompt to show some git information
    first install vcorompt https://github.com/djl/vcprompt
    then change the .bashrc file
    PS1=”\n\u@\h:\w \$(vcprompt -f ‘%b%m%u’)\n> “