git配置


1、用户信息:--global表示将下面信息写到~/.gitconfig文件


$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com


2、文本编辑器(默认使用vim)
$ git config --global core.editor emacs  //使用emacs


3、差异分析工具
$ git config --global merge.tool vimdiff  


查看配置信息
git config --list  //查看所有信息
git config user.name  //查看指定信息


获取帮助
git help
git help config
====================================================================
在工作目录中初始化新仓库
$ git init


将新文件纳入版本控制
$ git add filename




查看哪些文件处于什么状态
git status


如果是新添加的文件,那么一定是未跟踪文件 Untracked files


开始跟踪一个新文件,add就是放到暂存区
git add cxc


add之后如果修改cxc,那么还要再add一次


==================================================================
忽略某些文件,避免纳入git的管理
创建  .gitignore 文件
比如:
    # 此为注释 – 将被 Git 忽略
    # 忽略所有 .a 结尾的文件
    *.a
    # 但 lib.a 除外
    !lib.a
    # 仅仅忽略项目根目录下的 TODO 文件,不包括 subdir/TODO
    /TODO
    # 忽略 build/ 目录下的所有文件
    build/
    # 会忽略 doc/notes.txt 但不包括 doc/server/arch.txt
    doc/*.txt
===================================================================
查看差异
git status 比较简单 能查看修改过的文件  但不能知道修改了什么地方
git diff 可以查看修改未暂存的文件修改了什么地方
git diff --staged 可以查看已经暂存的文件修改了什么地方
git diff --staged 等价于 git diff --cached 命令


=====================================================================
现在暂存区域已经准备妥当可以提交了。
$ git commit     //提交的是暂存区里面的内容
$ git commit -m "add new file." // -m选项可以跟说明
$ git commit -a                 //-a选项可以省略 git add 即可以提交未暂存的内容


===========================================================================


移除文件  从仓库中移除
从跟踪文件清单中删除,也可以说从暂存区中删除,然后提交
git rm -f cxc

如果要从仓库中移除,但仍然留在目录中
$ git rm --cached cxc
=======================================================================


文件改名
git mv file_from file_to
上面这条命令相当于下面三条命令
$ mv README.txt README
    $ git rm README.txt
    $ git add README
=====================================================


查看提交历史
git log
可以有参数 具体查看 git help log
==============================================================================


撤销操作
$ git commit --amend  //撤销刚才的提交


取消已经暂存的操作
git reset HEAD cxc


取消对文件的修改
$ git checkout -- cxc  //比较危险
==============================================================================


查看当前的远程仓库
$ git remote   
origin
$ git remote -v
origin  https://github.com/forcxc/hello-world.git (fetch)
origin  https://github.com/forcxc/hello-world.git (push)
=====================================================================
添加远程仓库
git remote add test git://github.com/forcxc/test.git  命名为test方便后面使用 


git fetch test   //抓取远程仓库有而本地没有的,远程仓库必须存在
==============================================================================
推送数据到远程仓库
git push origin master


========================================================================


查看远程仓库信息
git remote show origin
============================================================================


远程仓库的重命名和删除
git remote rename old new  只是改在本地的简称
git remote rm new
=======================================================================
打标签
git tag  //列出标签
git tag -a v1.4 -m 'my version 1.4'  //新建标签


=================================================================


其他git技巧
命令别名
$ git config --global alias.co checkout
    $ git config --global alias.br branch
    $ git config --global alias.ci commit
    $ git config --global alias.st status