git简明使用

程序开发你会需要代码管理工具,fast version control 那就是git了。
一、本地测试
首先下载git  http://msysgit.github.io
安装好后打开bash开始体验一下:
  创建用户配置
  $ git config --global user.name "you name"
  $ git config --global user.email youemail@yahoo.com
  看一下配置
  $ git config --list
  可以看到你刚刚配的用户名、email
  $ git help
  有很多的cmmand 
 
简单的体验一下:
1.创建一个repository
在电脑e盘建一个文件夹 log
$ cd /e/log
$ git init
2.在log目录新建编辑一个文件tin.txt (在工作区) ,并提交到repository
$ git add tin.txt                          (加到缓存区)
$ git commit -m 'first commit'        (提交到仓库)
3.修改一下tin.txt ,并执行 add 和 commit的命令,
看下两次版本的记录
$ git log
 
commit 5cd41c8f0c0f1b798cde1ef4ee71e41269c3c43a

Author: tinin <tintindeng@gmail.com>
Date: Tue Sep 16 13:24:54 2014 +0800

modified tin

commit 8175e287683f37e905cb9056838ac068c298418c
Author: tinin <tintindeng@gmail.com>
Date: Tue Sep 16 13:14:26 2014 +0800

first

4.回到修改前的版本
$ git reset --hard 8175e
 
HEAD is now at 8175e28 first
看下版本记录
$ git log --pretty=oneline

8175e287683f37e905cb9056838ac068c298418c first

5.回到修改后的版本

先看下啊版本记录

$ git reflog

8175e28 HEAD@{0}: reset: moving to 8175e
5cd41c8 HEAD@{1}: commit: modified tin
8175e28 HEAD@{3}: commit (initial): first

$ git reset --hard 5cd41

又回来了

 

二、远程连接github

github地址 https://github.com/

注册好帐号并登录

1.create一个仓库(小加号)

找到仓库的连接拷贝下来

2.同过git命令行clone仓库到本地

$ git clone https://github.com/tintindeng/androidexample.git

3.远程提交代码

生成密钥(用来提交代码安全认证)

$ ssh-keygen -t rsa -C 'tintindeng@gmail.com'
....
The key's randomart image is:
+--[ RSA 2048]----+
| .o*+* |
| +.O B |
| + * * |
| . o + . |
| . . S |
| . . |
| E . . . |
| . . |
| |
+-----------------+

接下来到github上添加你生成的publickey

关联到远程仓库 和push到仓库

$ git remote add origin https://github.com/tintindeng/androidexample.git

$ git push origin master          (输入你的用户名密码)

在github你的仓库下可以看到你提交的文件了

另外github提供了图像化界面客户端 https://github.com/ 首页就看到下载的button

可以down下来体验下

 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

posted on 2014-09-16 15:29  tintindeng  阅读(130)  评论(0)    收藏  举报

导航