转 GitHub超详细图文攻略

 

    GitHub是程序员的社区,在里面能够学到不少书上学不到的东西。html

 

    GitHub操做总结 : 总结看不明白就看下面的详细讲解.java

 

    GitHub操做流程 :git

 

第一次提交 :  程序员

方案一 : 本地建立项目根目录, 而后与远程GitHub关联, 以后的操做同样;github

-- 初始化git仓库 :git init ;web

-- 提交改变到缓存 :git commit -m 'description' ;shell

-- 本地git仓库关联GitHub仓库 : git remote add origin git@github.com:han1202012/TabHost_Test.git ;windows

-- 提交到GitHub中 : git push -u origin master ;浏览器

方案二 方案二就是不用关联GitHub仓库, 直接从GitHub冲克隆源码到本地, 项目根目录也不用建立;缓存

-- 从GitHub上克隆项目到本地 :git clone git@github.com:han1202012/NDKHelloworld.git , 注意克隆的时候直接在仓库根目录便可, 不用再建立项目根目录 ;

-- 添加文件 :git add ./* , 将目录中全部文件添加;

-- 提交缓存 :git commit -m '提交';

-- 提交到远程GitHub仓库 : git push -u origin master ;

以后修改提交 : 

-- 与GitHub远程仓库同步 :git pull ;

-- 查看文件变动 : git status ;

-- 提交代码到本地缓存 : git commit -m 'description';

--提交代码到远程GitHub仓库 :git push ;

 

.gitignore用法 : 开放模式 注明忽略的文件 直接列出文件名, 保守模式 注明保留的文件 !文件名 ;

 

Git标签操做 : 轻量级标签, 带注释标签;

--查看标签 :git tag ;

--添加标签 : 轻量级标签git tag tagName , 带注释标签git tag -a tagName -m 'description' ;

--删除标签 :git tag -d tagName ;

--提交标签到GitHub中 : git push origin --tags ;

 

Git分支操做: 建立分支后, 分支操做不会影响master分支, 可是master分支改变会影其它分支;

--列出分支 :git branch ;

--切换分支 :git checkout master ;

--提交分支 : git push origin branchName ;

--删除分支 : git branch -d branchName , 强制删除分支 git branch -D branchName ;

--合并分支 : git merge branchName ;

 

.

一. Git介绍

 

分布式 : Git版本控制系统是一个分布式的系统, 是用来保存工程源代码历史状态的命令行工具;

 

保存点 : Git的保存点能够追踪源码中的文件, 并能获得某一个时间点上的整个工程项目额状态; 能够在该保存点将多人提交的源码合并, 也能够会退到某一个保存点上;

 

Git离线操做性 :Git能够离线进行代码提交, 所以它称得上是彻底的分布式处理, Git全部的操做不须要在线进行; 这意味着Git的速度要比SVN等工具快得多,  由于SVN等工具须要在线时才能操做, 若是网络环境很差, 提交代码会变得很是缓慢; 

 

Git基于快照 : SVN等老式版本控制工具是将提交点保存成补丁文件, Git提交是将提交点指向提交时的项目快照, 提交的东西包含一些元数据(做者, 日期, GPG等);

 

Git的分支和合并 : 分支模型是Git最显著的特色, 由于这改变了开发者的开发模式, SVN等版本控制工具将每一个分支都要放在不一样的目录中, Git能够在同一个目录中切换不一样的分支;

分支即时性 : 建立和切换分支几乎是同时进行的, 用户能够上传一部分分支, 另一部分分支能够隐藏在本地, 没必要将全部的分支都上传到GitHub中去;

分支灵活性 : 用户能够随时 建立 合并 删除分支, 多人实现不一样的功能, 能够建立多个分支进行开发, 以后进行分支合并, 这种方式使开发变得快速, 简单, 安全;

 

二. Git通用客户端(msysgit)

 

1. 下载Git客户端

 

Git客户端下载地址 :https://code.google.com/p/msysgit/downloads/list 将地址复制到浏览器栏便可下载.

 

2. 安装Git客户端

 

欢迎界面 : 直接下一步;

 

协议 : 必须接受;

 

安装位置 : 预留100M空间, 自定义安装位置;

 

选择安装组件 :也能够默认选择;

-- 图标组件(Addition icons) : 选择是否建立快速启动栏图标 或者 是否建立桌面快捷方式;

-- 桌面浏览(Windows Explorer integration) : 浏览源码的方法, 单独的上下文浏览 只使用bash 或者 只用Git GUI工具; 高级的上下文浏览方法 使用git-cheetah plugin插件;

-- 关联配置文件 : 是否关联git配置文件, 该配置文件主要显示文本编辑器的样式;

-- 关联shell脚本文件 : 是否关联Bash命令行执行的脚本文件;

-- 使用TrueType编码 : 在命令行中是否使用TruthType编码, 该编码是微软和苹果公司制定的通用编码; 

 

开始菜单快捷方式目录 : 设置开始菜单中快捷方式的目录名称, 也能够选择再也不开始菜单中建立快捷方式;

 

设置环境变量 : 选择使用什么样的命令行工具, 通常状况下咱们默认使用Git Bash便可, 默认选择;

-- Git自带 : 使用Git自带的Git Bash命令行工具;

-- 系统自带CMD : 使用Windows系统的命令行工具;

-- 两者都有 : 上面两者同时配置, 可是注意, 这样会将windows中的find.exe 和 sort.exe工具覆盖, 若是不懂这些尽可能不要选择; 

 

选择换行格式 : 

-- 检查出windows格式转换为unix格式 : 将windows格式的换行转为unix格式的换行在进行提交;

-- 检查出原来格式转为unix格式 : 无论什么格式的, 一概转为unix格式的换行在进行提交;

-- 不进行格式转换 : 不进行转换, 检查出什么, 就提交什么;

 

开始安装 : 

 

安装结束 : over;

 

3. 配置GitHub

 

修改Git Bash的配置 : 将Git Bash设置为快速编辑模式, 能够更好的使用该命令行工具 : 

 

(1) 建立本地ssh

 

使用命令 : 建立本地ssh

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. ssh-keygen -t rsa -C "13241153187@163.com"  

GitHub邮箱 : 该命令后面的邮箱就是GitHub的注册邮箱

 

路径选择 : 使用该命令以后, 会出现提示选择ssh-key生成路径, 这里直接点回车默认便可, 生成的ssh-key在默认路径中;

密码确认 : 这里咱们不使用密码进行登陆, 用密码太麻烦;

 

(2) 将ssh配置到GitHub中

 

进入生成的ssh目录 : C:\Documents and Settings\Administrator\.ssh 中, 使用记事本打开 id_rsa.pub 文件, 将该文件中的内容复制;

id_rsa.pub 文件内容 : 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAtT1YCeaNulpfC+ARqAWrCdfpi6CpW3gkGT0hp6Q8by7NnEfy4dah9CwSrNbWJH5eS4tiqckE+bdbSVNvAboFD1MtGZjtzE4GDweG/6J/SDYV/ADFN/RLWGb+5rQ8wMCjc/fODgLJDFxk1Fwk/TTqTcbtLab1toLcts3zGIW5DstA3RQ0CCX/sPew5m7vh7DcKXluj2TBd9hw== 13241153187@163.com  


进入GitHub网站 : 登陆GitHub, 选择Account Setting 用户设置 : 

 



选择左侧的SSH-KEY选项 : 

 

点击右侧的Add SSH key :

 

 

将上面复制好的ssh-key复制进去 : 

 

验证是否配置成功 : 

使用命令 : 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. ssh -T git@github.com  

 

成功提示 : 若是出现Hi han1202012! You've successfully authenticated, but GitHub does not provide shell access. 就说明配置成功, 能够链接上GitHub;

 

(3) 配置本地用户和邮箱

 

用户名邮箱做用 : 咱们须要设置一个用户名 和 邮箱, 这是用来上传本地仓库到GitHub中, 在GitHub中显示代码上传者;

使用命令 : 

 

[java]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git config --global user.name "HanShuliang" //设置用户名  
  2. git config --global user.email "13241153187@163.com"  //设置邮箱  


 

 

4. Git Bash提交源码到GitHub

 

(1) GitHub中建立一个工程

 

工程的https地址: https://github.com/han1202012/TabHost_Test.git .

工程的SSH地址 : git@github.com:han1202012/TabHost_Test.git .

 

GitHub提示生成的命令 : 

-- Create a new repository on the command line : 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. touch README.md  
  2. git init  
  3. git add README.md  
  4. git commit -m "first commit"  
  5. git remote add origin git@github.com:han1202012/TabHost_Test.git  
  6. git push -u origin master  


-- Push an existing repository from the command line : 

 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git remote add origin git@github.com:han1202012/TabHost_Test.git  
  2. git push -u origin master  



 

(2) 初始化git目录

 

使用命令 : 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git init  


若是不执行这条命令, 就会出现错误 : fatal: Not a git repository (or any of the parent directories): .git .

 

 

(3) 添加文件

 

使用命令 : 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git add ./*  

 

 

可能会报出一些警告, 不用理会 : 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. warning: LF will be replaced by CRLF in AndroidManifest.xml.  
  2. The file will have its original line endings in your working directory.  
  3. warning: LF will be replaced by CRLF in bin/AndroidManifest.xml.  
  4. The file will have its original line endings in your working directory.  
  5. warning: LF will be replaced by CRLF in gen/shuliang/han/tabhost_test/BuildConfig.java.  


将仓库中的全部文件添加到缓存中;

 

 

(4) 提交缓存

 

使用命令 : 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git remote add origin git@github.com:han1202012/TabHost_Test.git  


将添加或者改变的内容提交到缓存中;

 

 

(5) 将Git本地缓存提交到GitHub中

 

使用命令 : 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git push -u origin master  

 

执行该命令, 源码就被提交到了GitHub 中;

 

 

.

做者 :万境绝尘 

转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/18812279

.

 

三. Git的一些用法

 

1. .gitignore文件

 

屏蔽文件 : .gitignore文件是告诉Git哪些目录或者文件须要忽略, 这些文件将不被提交; 

经常使用场景 : 写完代码后会执行变异调试等操做, 使用 .gitignore 文件将这些编译后的文件屏蔽, 这些文件不须要Git工具进行管理;

Android中的.gitignore : 在Android中 bin 和 gen 两个目录能够忽略;

.gitignore位置 : 项目根目录下;

 

过滤模式 : Git中的 .gitignore 中有两种模式,开放模式 和保守模式,保守模式的优先级要高于开放模式;

 

开放模式 : 设置哪些文件 活 目录 被过滤, 凡是在文件中列出的文件或者目录都要被过滤掉;

-- 过滤目录 : /bin/ 就是将bin目录过滤, 该文件下的全部目录和文件都不被提交;

-- 过滤某个类型文件 : *.zip *.class 就是过滤zip 和 class 后缀的文件, 这些文件不被提交;

-- 过滤指定文件 : /gen/R.java, 过滤该文件, 该文件不被提交;

 

保守模式 : 设置哪些文件不被过滤, 凡是列在其中的文件都要完整的提交上去;

-- 跟踪目录 : !/src , 该目录下的全部文件都要被提交;

-- 跟踪某类文件 : !*.java , 凡是java文件都要保留;

-- 跟踪指定文件 : !/AndroidManifest.xml , 该文件须要保留, 提交上去;

 

配置原则 : 通常状况下采用开放模式鱼保守模式共同使用;

eg : 一个目录下有不少目录和文件, 当咱们只须要保留其中的一个文件的时候, 先用开放模式不保留这些文件, 而后用保守模式将这个文件留下来, 保守模式的优先级要高于开放模式;

 

2. 标签使用(Tag)

 

标签做用: 在开发的一些关键时期,使用标签来记录这些关键时刻, 例如发布版本, 有重大修改, 升级的时候, 会使用标签记录这些时刻, 来永久标记项目中的关键历史时刻;

 

查看标签: 列出的标签安装ASCII字母顺序肯定, 排序没有很明确的意义;

-- 列出全部的标签 :  

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git tag  

-- 使用限定列出限定后的标签 : 

 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git tag -l v1.*  




 

标签分类 : Git中的标签分为 轻量级标签(lightweight) 和 带注释的标签(annotated), 通常状况下推荐使用带注释的标签, 若是标签是临时的能够采用轻量级标签;

-- 轻量级标签 : 轻量级标签中的信息含量不多, 这种标签只表明某时刻代码的提交, 至关于指向这个提交的指针;

-- 带注释标签 : 这种标签是一种校验和, 包含标签名, 邮箱, 日期, 标签信息, GPG签名 和 验证, 它至关于一个对象, 封装了这些信息;

 

建立标签 :

-- 建立轻量级标签 : 这样的标签没有附带其它的信息;

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git tag v2.0  

 

-- 建立带注释标签 : -m 后跟的是注释信息, 当使用git show v2.1的时候, 会显示这个注释信息;

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git tag -a v2.1 -m 'first version'  


-- 建立GPG私钥的注释标签 : 

 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git tag -s v2.1 -m 'GPG version'  

 

在本机上实验不成功 出现下面的错误 : 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. Administrator@XRDPTJ9ILK6IWRA /storage/TabHost_Test (master)  
  2. $ git tag -s v2.2 -m 'GPG version'  
  3. gpg: error loading `iconv.dll': 找不到指定的模块。  
  4.   
  5. gpg: please see http://www.gnupg.org/download/iconv.html for more information  
  6. gpg: keyblock resource `c:/Documents and Settings/Administrator/.gnupg\secring.g  
  7. pg': file open error  
  8. gpg: keyblock resource `c:/Documents and Settings/Administrator/.gnupg\pubring.g  
  9. pg': file open error  
  10. gpg: skipped "HanShuliang <13241153187@163.com>": secret key not available  
  11. gpg: signing failed: secret key not available  
  12. error: gpg failed to sign the data  
  13. error: unable to sign the tag  

之后再找缘由;

 

-- 为以前的提交添加标签 : 先使用 git log --oneline 命令列出以前的提交, 会有一个七位的十六进制数进行标记, 使用git tag -a v3.1 f1bb97a 命令便可为这个提交添加标签;

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. $ git log --oneline  
  2.   
  3. f1bb97a first commit  
  4.   
  5. git tag -a v3.1 f1bb97a  



 

删除标签 : 使用命令 git tag -d 标签名 命令删除标签;

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git tag -d v0.1  




 

验证标签 : 提交了GPG带注释标签才能够验证, 由于上面没有提交成功, 这里留下一个命令;

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git tag -v v1.0  



 

共享标签 : 即将标签提交到GitHub中;

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git push origin --tags  



 

 

3. 分支和合并

 

(1) 查看现存分支

 

查看现存分支 : git branch命令;

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git branch  


从结果能够看出, 如今只有一个分支master;

 

 

(2) 建立分支

 

建立分支 : git branch 分之名称, 就能够建立一个分支, 建立完分支之后能够查看分支, 当前使用的分支会显示成为绿色, 前面带有 "*", 若是不是当前使用的分支, 显示的是白色, 而且没有 "*" 前缀;

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git branch branch1  



 

(3) 切换分支

 

切换分支 : git checkout 分支名称, 切换分支之后, 在分支进行操做,文件的改变不会体如今master主分支中, 主分支改变, 会体如今其它分支中;

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git checkout branch1  



 

关于主分支和其它分支 : 

-- 分支编辑 : 现有两个分支 master 主分支, 和刚建立的branch1 分支, 切换到 branch1 分支, 在branch1 中建立一个文件 description_branch1.txt; 

-- 其它分支文件不会影响主分支 : 而后在切换回 master 主分支, 发现没有description_branch1.txt文件, 建立一个文件 description_master.txt;

-- 主分支会影响其它分支 : 在切换回 branch1 分支中, 发现存在 description_master.txt文件;

.

对比过程 : 

 

查看该工程项目分支状况 : 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git branch  

 

-- 分支结果 : 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. branch1  
  2. master  

 

 

切换到 branch1 分支 : 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git checkout branch1  

-- 切换结果 : 

 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. Switched to branch 'branch1'  

 

 

查看 branch1 分支下的文件 : 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. ls  

-- 查看文件结果 : 

 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. AndroidManifest.xml  ic_launcher-web.png   res  
  2. assets               libs                  src  
  3. bin                  proguard-project.txt  
  4. gen                  project.properties  


建立一个文件 : 

 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. touch description_branch1.txt  


添加这个文件到本地缓存 :

 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git add description_branch1.txt  


提交本地缓存 : 注意, 这里必须提交, 若是不提交缓存, 这个文件在主分支也会出现;

 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git commit -m 'add a description of branch1'  

-- 提交结果结果 : 

 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. [branch1 7f5785e] add a description of branch1  
  2.  1 file changed, 0 insertions(+), 0 deletions(-)  
  3.  create mode 100644 description_branch1.txt  


查看该分支下的文件 : 

 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. ls  

-- 查看文件结果 : 

 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. AndroidManifest.xml      libs  
  2. assets                   proguard-project.txt  
  3. bin                      project.properties  
  4. <strong>description_branch1.txt</strong>  res  
  5. gen                      src  
  6. ic_launcher-web.png  


切换回主分支 : 

 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git checkout master  

 

-- 切换分支结果 : 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. Switched to branch 'master'  
  2. Your branch is up-to-date with 'origin/master'.  

 

 

查看主分支文件 : 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. ls  

-- 查看文件结果 : 没有在 branch1 中添加的文件;

 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. AndroidManifest.xml  ic_launcher-web.png   res  
  2. assets               libs                  src  
  3. bin                  proguard-project.txt  
  4. gen                  project.properties  



.

 

 

(4) 提交分支 

 

提交分支命令 : 将本地的分支提交到 GitHub中;

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git push origin experiment  



 

(5) 分支合并移除

 

合并分支命令 : 合并分支以后, 分支中有的文件在 主分支中也会显示, 至关于将branch1 分支中的文件拷贝了一份到master分支中;

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git merge branch1  

合并结果 : 

 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. Updating f1bb97a..7f5785e  
  2. Fast-forward  
  3.  description_branch1.txt | 0  
  4.  1 file changed, 0 insertions(+), 0 deletions(-)  
  5.  create mode 100644 description_branch1.txt  

 

 



.

(6) 删除分支

 

删除分支命令 : 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git branch -d branch1  


强制删除分支命令 : 若是branch1 分支尚未被合并的话, Git是不容许删除这个分支的, 此时要想删除该分支, 就只能使用下面的命令强制删除该分支 : 

 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git branch -D branch1  



 

4. Git工做流程

 

(1) 两种工做流程

 

协做开发工做流程 : 这种状况是最复杂的状况, 多人团队共同开发一个项目;

-- 与远程仓库同步 : git pull ;

-- 修改文件 : 添加 删除 修改文件;

-- 查看变动 : git status ;

-- 载入变动 :添加文件, 先使用git add fileName, 在使用 git commit -m 'note' 载入变动; 若是是删除 修改文件, 直接使用 git commit -m 'note' 提交;

-- 重复 : 重复执行 修改文件 查看变动 载入变动 提交载入动做;

-- 上传 : 使用 git push 命令将项目源码提交带GitHub中去;

 

单独开发工做流程 : 若是是我的独立开发, 仅追踪本地文件变动, 就不须要提交到服务器上, 由于Git是分布式的;

-- 修改文件 : 

-- 提交变动 : 

-- 重复 : 

 

(2) 简单示例

 

1> 独立开发示例

 

该示例不会上传, 仅在本地进行操做;

 

从GitHub中检出项目源码 : 注意, 检出的源码是根目录源码, 咱们在总仓库的根目录检出便可,不一样再为项目建立目录;

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git clone git@github.com:han1202012/AndroidPictureViewer.git  

-- 检出克隆结果 : 

 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. Cloning into 'AndroidPictureViewer'...  
  2. remote: Counting objects: 86, done.  
  3. remote: Compressing objects: 100% (62/62), done.  
  4. remote: Total 86 (delta 3), reused 86 (delta 3)  
  5. Receiving objects: 100% (86/86), 1.67 MiB | 109.00 KiB/s, done.  
  6. Resolving deltas: 100% (3/3), done.  
  7. Checking connectivity... done.  


删除bin和gen目录 : 这两个目录是Android工程编译产生的临时文件, 没有必要上传到GitHub中去;

 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. rm -rf bin gen  

-- 查看删除结果状态 : 

 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git status  

-- 结果 : 

 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. On branch master  
  2. Your branch is up-to-date with 'origin/master'.  
  3.   
  4. Changes not staged for commit:  
  5.   (use "git add/rm <file>..." to update what will be committed)  
  6.   (use "git checkout -- <file>..." to discard changes in working directory)  
  7.   
  8.         deleted:    bin/AndroidManifest.xml  
  9.         deleted:    bin/ImageView_Test.apk  
  10.         deleted:    bin/classes.dex  
  11.         deleted:    bin/res/crunch/drawable-xxhdpi/ic_launcher.png  
  12.         deleted:    bin/resources.ap_  
  13.         deleted:    gen/shuliang/han/imageview_test/BuildConfig.java  
  14.         deleted:    gen/shuliang/han/imageview_test/R.java  

 

 

提交缓存 : 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git commit -a  

-- 提交结果 : 

 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. [master e4377ba] delete bin and gen directory.  
  2.  28 files changed, 2 insertions(+), 110 deletions(-)  
  3.  create mode 100644 .gitignore  
  4.  delete mode 100644 bin/AndroidManifest.xml  
  5.  delete mode 100644 bin/ImageView_Test.apk  
  6.  delete mode 100644 bin/classes.dex  
  7.  delete mode 100644 bin/resources.ap_  
  8.  delete mode 100644 gen/shuliang/han/imageview_test/BuildConfig.java  
  9.  delete mode 100644 gen/shuliang/han/imageview_test/R.java  

 

2> 协做开发示例

 

与远程仓库同步 : 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git pull  

-- 若是其余人没有提交项目到GitHub上, 就会出现下面结果 : 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. Already up-to-date.  


修改文件后查看变动 : 

 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git status  

-- 若是没有变动会出现下面状况 : 

 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. On branch master  
  2. Your branch is ahead of 'origin/master' by 1 commit.  
  3.   (use "git push" to publish your local commits)  
  4.   
  5. nothing to commit, working directory clean  


载入变动 : 若是有变动, 那么使用命令载入变动. 使用 git commit -a 或者 git add 命令;

 

-- 添加文件 : 先使用 git add 文件名 来添加文件到缓存, 以后使用 git commit -m '' 命令提交代码到本地缓存;

-- 删除改变文件 : 直接使用 git commit -m '', 提交删除 或则 改变 到本地缓存;

 

提交项目源码到服务器 : 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. git push  

-- 提交源码结果 : 

 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. warning: push.default is unset; its implicit value is changing in  
  2. Git 2.0 from 'matching' to 'simple'. To squelch this message  
  3. and maintain the current behavior after the default changes, use:  
  4.   
  5.   git config --global push.default matching  
  6.   
  7. To squelch this message and adopt the new behavior now, use:  
  8.   
  9.   git config --global push.default simple  
  10.   
  11. See 'git help config' and search for 'push.default' for further information.  
  12. (the 'simple' mode was introduced in Git 1.7.11. Use the similar mode  
  13. 'current' instead of 'simple' if you sometimes use older versions of Git)  
  14.   
  15. Counting objects: 4, done.  
  16. Delta compression using up to 2 threads.  
  17. Compressing objects: 100% (2/2), done.  
  18. Writing objects: 100% (3/3), 292 bytes | 0 bytes/s, done.  
  19. Total 3 (delta 1), reused 0 (delta 0)  
  20. To git@github.com:han1202012/AndroidPictureViewer.git  
  21.    1ddf8c7..e4377ba  master -> master  



 

查看GitHub中的源码状况 : gen 和 bin 目录果真被删除了;

转自:http://blog.csdn.net/shulianghan/article/details/18812279

相关文章
相关标签/搜索