记录下James工作中遇到的问题:

1. 在app目录下提交.cfg特制化文件,此时Git和Gerrit结合使用;

2. 对修改文件追加提交;

3. 查看当前目录的所有分支,包括:本地分支和远程分支;

4. 根据远程分支创建分支,并查看所有分支与远程分支的对应关系;

5. 切换分支前,保存当前分支的修改;并在返回时,恢复修改;

6. 在本地文件系统中,建立远程仓库并克隆仓库,在本地仓库中提交更新;

7. 删除服务器端文件内容,并提交删除修改;

上述问题分析:

1. 在app目录下提交.cfg特制化文件,使用场景:Git和Gerrit结合使用;要知道Gerrit是代码审核的工具。

提交代码和文件(是app文件夹下的内容),需要进入.git目录,执行以下步骤:

1. (首先需要查看哪些文件被改动)git add assets/cfg_k86s7_KST-T5.cfg

2. git st // 查看add指令执行结果(优先检测仓库是否有更新)git fetch // 检测远程是否有更新,如果有更新(增加了新的代码)-> 需要先执行 git pull

3. git ci -m "add cfg_k86s7_KST-T5.cfg" // commit 相当于提交命令;其后代表此次的注释

4. git lg // 查看log,检查此次的指令执行结果;

5. git push origin HEAD:refs/for/master  //提交至服务器,需要审核!

6. 检测是否push到远程分支,查看gerrit2.y/服务器;

上述最需要解答的疑问是:为什么需要使用“git push origin HEAD:refs/for/master”。既然是使用Gerrit作为代码审核工具,就需要遵循push的规范;上述提交指令就是提交审核的规范。

2. 对已经push到Gerrit服务器上的Commit追加提交。

1. mv assets/cfg_k86s7_HC_CDJ7801.cfg(source) assets/cfg_k86s7_HC-CDJ7801.cfg(destination) (重命名文件)

2. git add assets/

3. git commit assets/ --amend

4. git push origin HEAD:refs/for/master

更新提交内容,可能的使用场景有:再次修改文件;增加修改...对“git commit ...”增加参数:—amend即可实现commit修改。

3. 查看当前目录的所有分支,包括:本地分支和远程分支。

git branch -a

上述指令不仅可以获取到本地分支情况,还可以获取到远程分支情况。

git branch -vv

上述指令则可以获取当前HEAD指向的远程分支情况。

4. 根据远程分支创建分支,并查看所有分支与远程分支的对应关系。

Administrator@ZHANGFENG /f/sptSrcGit/FactoryTest (develop)
$ git branch -a
* develop
remotes/origin/HEAD -> origin/master
remotes/origin/develop
remotes/origin/mx1/teyes/t7
remotes/origin/test
Administrator@ZHANGFENG /f/sptSrcGit/FactoryTest (develop)
$ git checkout -b mx1/teyes/t7 origin/mx1/teyes/t7
Branch mx1/teyes/t7 set up to track remote branch mx1/teyes/t7 from origin.
Switched to a new branch 'mx1/teyes/t7'
Administrator@ZHANGFENG /f/sptSrcGit/FactoryTest (mx1/teyes/t7)
$ git status
On branch mx1/teyes/t7
Your branch is up-to-date with 'origin/mx1/teyes/t7'.
nothing to commit, working directory clean

使用“git checkout -b ...”,参数-b则是创建分支;上述指令达到创建并切换分支的目的。

5. 切换分支前,保存当前分支的修改;并在返回时,恢复修改。

Administrator@ZHANGFENG /f/sptSrcGit/FactoryTest (develop)
$ git stash
Saved working directory and index state WIP on develop: 9c721b0 解决无SN号或IMEI号时,可能引发的崩溃问题;解决GPS测试项中点击HOME按键,导致其他测试项结果错误问题;增加ADAS测试项
HEAD is now at 9c721b0 解决无SN号或IMEI号时,可能引发的崩溃问题;解决GPS测试项中点击HOME按键,导致其他测试项结果错误问题;增加ADAS测试项
Administrator@ZHANGFENG /f/sptSrcGit/FactoryTest (develop)
$ git stash pop
On branch develop
Your branch is up-to-date with 'origin/develop'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: .classpath
modified: local.properties
modified: src/com/spt/view/SptActivity.java
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (44cfaa42768ef50d6b82db4c2e8d2dee508b00b4)

上述指令则是执行:保存修改,恢复修改的作用。

6. 在本地文件系统中,建立远程仓库并克隆仓库,在本地仓库中提交更新。

步骤1:创建本地分支

james@james-PC MINGW64 /d/GitDemo
$ cd remoteGit/
james@james-PC MINGW64 /d/GitDemo/remoteGit
$ git init --bare
Initialized empty Git repository in D:/GitDemo/remoteGit

步骤2:在本地创建克隆上述仓库(远程仓库),并作为本地仓库使用

james@james-PC MINGW64 /d/GitDemo/demo
$ git clone ../remoteGit/
Cloning into 'remoteGit'...
warning: You appear to have cloned an empty repository.
done.
james@james-PC MINGW64 /d/GitDemo/demo
$ ls
remoteGit/

步骤3:在上述本地仓库中,创建a.txt文件,并提交到远程分支

james@james-PC MINGW64 /d/GitDemo/demo/remoteGit (master)
$ echo 111 >> a.txt
james@james-PC MINGW64 /d/GitDemo/demo/remoteGit (master)
$ cat a.txt
111
james@james-PC MINGW64 /d/GitDemo/demo/remoteGit (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: a.txt
no changes added to commit (use "git add" and/or "git commit -a")
james@james-PC MINGW64 /d/GitDemo/demo/remoteGit (master)
$ git add .
warning: LF will be replaced by CRLF in a.txt.
The file will have its original line endings in your working directory.
james@james-PC MINGW64 /d/GitDemo/demo/remoteGit (master)
$ ls
a.txt
james@james-PC MINGW64 /d/GitDemo/demo/remoteGit (master)
$ cat a.txt
111
james@james-PC MINGW64 /d/GitDemo/demo/remoteGit (master)
$ ls
a.txt
james@james-PC MINGW64 /d/GitDemo/demo/remoteGit (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: a.txt
james@james-PC MINGW64 /d/GitDemo/demo/remoteGit (master)
$ git commit -m "add 111 to a.txt"
[master 07e3fc3] add 111 to a.txt
1 file changed, 1 insertion(+)
james@james-PC MINGW64 /d/GitDemo/demo/remoteGit (master)
$ git push origin HEAD
Counting objects: 3, done.
Writing objects: 100% (3/3), 256 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To D:/GitDemo/demo/../remoteGit/
bdaf647..07e3fc3 HEAD -> master

上述使用 git push origin HEAD,其中:HEAD指向的是本地的当前分支master(如果当前分支是develop,则HEAD则代表develop分支);表示:将本地工作分支推送到远程的该工作分支(master或其他分支)。

步骤4:在本地仓库中,根据远程的master分支新建develop_test分支,并提交更新到远程的master分支中

james@james-PC MINGW64 /d/GitDemo/demo/remoteGit (master)
$ git checkout -b develop_test origin/master
Branch develop_test set up to track remote branch master from origin.
Switched to a new branch 'develop_test'
james@james-PC MINGW64 /d/GitDemo/demo/remoteGit (develop_test)
$ ls
a.txt
james@james-PC MINGW64 /d/GitDemo/demo/remoteGit (develop_test)
$ cat a.txt
111
james@james-PC MINGW64 /d/GitDemo/demo/remoteGit (develop_test)
$ cat 222 >> a.txt
cat: 222: No such file or directory
james@james-PC MINGW64 /d/GitDemo/demo/remoteGit (develop_test)
$ echo 222 >> a.txt
james@james-PC MINGW64 /d/GitDemo/demo/remoteGit (develop_test)
$ git status
On branch develop_test
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: a.txt
no changes added to commit (use "git add" and/or "git commit -a")
james@james-PC MINGW64 /d/GitDemo/demo/remoteGit (develop_test)
$ git add .
warning: LF will be replaced by CRLF in a.txt.
The file will have its original line endings in your working directory.
james@james-PC MINGW64 /d/GitDemo/demo/remoteGit (develop_test)
$ git commit -m "add 222 to a.txt in develop_test branch"
[develop_test c522e2e] add 222 to a.txt in develop_test branch
1 file changed, 1 insertion(+)
james@james-PC MINGW64 /d/GitDemo/demo/remoteGit (develop_test)
$ git branch -vv
* develop_test c522e2e [origin/master: ahead 1] add 222 to a.txt in develop_test branc h
master 07e3fc3 [origin/master] add 111 to a.txt
james@james-PC MINGW64 /d/GitDemo/demo/remoteGit (develop_test)
$ git push origin HEAD:master
Counting objects: 3, done.
Writing objects: 100% (3/3), 280 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To D:/GitDemo/demo/../remoteGit/
07e3fc3..c522e2e HEAD -> master

上述使用: git push origin HEAD:master 表示将当前工作分支develop的更新,提交到远程的master分支。

步骤5:验证远程的master已改变

james@james-PC MINGW64 /d/GitDemo/demo/remoteGit (develop_test)
$ git checkout master
Switched to branch 'master'
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
(use "git pull" to update your local branch)
james@james-PC MINGW64 /d/GitDemo/demo/remoteGit (master)
$ git fetch
james@james-PC MINGW64 /d/GitDemo/demo/remoteGit (master)
$ git pull
Updating 07e3fc3..c522e2e
Fast-forward
a.txt | 1 +
1 file changed, 1 insertion(+)
james@james-PC MINGW64 /d/GitDemo/demo/remoteGit (master)
$ cat a.txt
111
222

下述是本地仓库中保存的.git目录:

james@james-PC MINGW64 /d/GitDemo/localGit/remoteGit (master)
$ ls -al
total 5
drwxr-xr-x 1 james 197121 0 十一 20 08:41 ./
drwxr-xr-x 1 james 197121 0 十一 20 08:37 ../
drwxr-xr-x 1 james 197121 0 十一 20 08:41 .git/
-rw-r--r-- 1 james 197121 10 十一 20 08:41 a.txt

或者使用另外一种方式验证:

james@james-PC MINGW64 /d/GitDemo
$ cd remoteGit/
james@james-PC MINGW64 /d/GitDemo/remoteGit (BARE:master)
$ git log
commit c522e2e50b79aac1be118b48ca7629f38356b296
Author: ZHANGEfeng-james <zfengwust3054@163.com>
Date: Sat Nov 19 23:36:22 2016 +0800
add 222 to a.txt in develop_test branch
commit 07e3fc35d829b9cd6ff311a6a525b97d1e501612
Author: ZHANGEfeng-james <zfengwust3054@163.com>
Date: Sat Nov 19 23:09:47 2016 +0800
add 111 to a.txt
commit bdaf647cfa610d73733060ae46c4c1ee8e3857b0
Author: ZHANGEfeng-james <zfengwust3054@163.com>
Date: Sat Nov 19 23:05:20 2016 +0800
init master

如上所示,即实现了远程分支和本地分支的创建和提交操作。

7. 删除服务器端文件内容,并提交删除修改

Administrator@ZHANGFENG /f/sptSrcGit/CarDoc (master)
$ git rm 应用开发一部/设计文档/工厂测试程序设计文档_张峰_11.21.doc
rm '应用开发一部/设计文档/工厂测试程序设计文档_张峰_11.21.doc'
Administrator@ZHANGFENG /f/sptSrcGit/CarDoc (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: 测试程序设计文档_11.21.doc
Administrator@ZHANGFENG /f/sptSrcGit/CarDoc (master)
$ git commit -m "删除测试程序设计文档,已更新至24日文件"
[master 659232c] 删除测试程序设计文档,已更新至24日文件
1 file changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 测试程序设计文档_11.21.doc
Administrator@ZHANGFENG /f/sptSrcGit/CarDoc (master)
$ git push origin HEAD:refs/for/master
Counting objects: 17, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 503 bytes | 0 bytes/s, done.
Total 4 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2)
remote: Processing changes: new: 1, refs: 1, done
remote:
remote: New Changes:
remote: http://gerrit.y/3244 删除测试程序设计文档,已更新至24日文件
remote:
To ssh://zhangfeng@gerrit.y:29419/yunovo_packages/CarDoc
* [new branch] HEAD -> refs/for/master

涉及到的git指令:git rm <file-name>。

Git使用实例分析的更多相关文章

  1. gpgpu-sim卡分配程序设计实例分析

    gpgpu-sim卡分配程序设计实例分析 运行代码地址:https://github.com/gpgpu-sim/gpgpu-sim_distribution 一.概述 此文件包含有关安装.生成和运行 ...

  2. RPC原理及RPC实例分析

    在学校期间大家都写过不少程序,比如写个hello world服务类,然后本地调用下,如下所示.这些程序的特点是服务消费方和服务提供方是本地调用关系. 1 2 3 4 5 6 public class ...

  3. java基础学习05(面向对象基础01--类实例分析)

    面向对象基础01(类实例分析) 实现的目标 1.如何分析一个类(类的基本分析思路) 分析的思路 1.根据要求写出类所包含的属性2.所有的属性都必须进行封装(private)3.封装之后的属性通过set ...

  4. (转)实例分析:MySQL优化经验

    [IT专家网独家]同时在线访问量继续增大,对于1G内存的服务器明显感觉到吃力,严重时甚至每天都会死机,或者时不时的服务器卡一下,这个问题曾经困扰了我半个多月.MySQL使用是很具伸缩性的算法,因此你通 ...

  5. sql注入实例分析

    什么是SQL注入攻击?引用百度百科的解释: sql注入_百度百科: 所谓SQL注入,就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令.具 ...

  6. 实例分析ELF文件静态链接

    参考文献: <ELF V1.2> <程序员的自我修养---链接.装载与库>第4章 静态链接 开发平台: [thm@tanghuimin static_link]$ uname ...

  7. 用实例分析H264 RTP payload

    用实例分析H264 RTP payload H264的RTP中有三种不同的基本负载(Single NAL,Non-interleaved,Interleaved) 应用程序可以使用第一个字节来识别. ...

  8. nodejs的模块系统(实例分析exprots和module.exprots)

    前言:工欲善其事,必先利其器.模块系统是nodejs组织管理代码的利器也是调用第三方代码的途径,本文将详细讲解nodejs的模块系统.在文章最后实例分析一下exprots和module.exprots ...

  9. Android Touch事件原理加实例分析

    Android中有各种各样的事件,以响应用户的操作.这些事件可以分为按键事件和触屏事件.而Touch事件是触屏事件的基础事件,在进行Android开发时经常会用到,所以非常有必要深入理解它的原理机制. ...

随机推荐

  1. fgets读取文件时的注意事项

    1 文本文件 a.txt 内容如下 2 c代码 FILE *fil; if (!(fil = fopen("/home/rudy/projects/paser/a.txt", &q ...

  2. Oracle游标示例

    -- 声明游标:CURSOR cursor_name IS select_statement --For 循环游标 --(1)定义游标 --(2)定义游标变量 --(3)使用for循环来使用这个游标 ...

  3. Python-Tkinter几何布局管理(转)

    所有的Tkinter组件都包含专用的几何管理方法,这些方法是用来组织和管理整个父配件区中子配件的布局的.Tkinter提供了截然不同的三种几何管理类:pack.grid和place. pack() p ...

  4. Excel jxl导入导出

    JAVA EXCEL API简介 Java Excel是一开放源码项目,通过它Java开发人员可以读取Excel文件的内容.创建新的Excel文件.更新已经存在的Excel文件.使用该API非Wind ...

  5. js节点属性

    在文档对象模型 (DOM) 中,每个节点都是一个对象.DOM 节点有三个重要的属性 : 1. nodeName : 节点的名称 2. nodeValue :节点的值 3. nodeType :节点的类 ...

  6. WEB-INF下jsp跳转

    今天才知道:浏览器是不允许直接访问WEB-INF文件夹的 瞬间感觉自己好shi的有没有,纠结了2天 看来还得通过springMVC来跳,,,

  7. html text加提示语

    <input type="text" id="key" name="key" value=" 请输入关键词" on ...

  8. 《深入浅出 Java Concurrency》

    http://www.blogjava.net/xylz/archive/2010/07/08/325587.html

  9. Solr Cloud搭建

    1:搭建tomcat 配置connector: server.xm文件中: <Connector port="8080"maxThreads="200" ...

  10. redis cluster搭建

    一 .准备文件: Ruby :http://www.ruby-lang.org/en/downloads/    redis-3.0.5.tar.gz Redis:http://www.redis.c ...