/ 2018-08-15
一、Git介绍
1.Git概述
Git是类似于SVN等代码管理软件,使用分布式技术实现。Github是互联网代码仓库,每个人可以在上面创建自己的仓库,使用git完成同github仓库的代码同步等管理工作。

2.Git逻辑架构
git架构上分为远程仓库、本地仓库和工作空间。远程仓库就是位于GitHub上的仓库,本地仓库是为用户本机的仓库目录,工作空间是用户开发所处的目录。三者关系与操作如下图所示:

3.Git分支和标记
branch是分支,是一个独立发展的路线,成熟后会合并到master主分支上。
tag是分支推进过程中的里程碑,是一个记号。
4.Git帮助
# 查看所有命令 cmd>git help -a # cmd>git help -git
二、Github
使用git前需要在github上注册账号,并创建字节的仓库目录。流程如下:
1. 登录 github 网站
http://github.com
2. 注册用户

3. 激活账号
登录邮箱,激活账号即可。

4. 创建仓库

5. 查看 github 上仓库列表

6. github上的仓库
在setting选项卡中进行删除。如下图所示:

点击删除按钮后,弹出警告窗口:

输入确认删除的仓库名称后,最后才可删除!

三、Git安装、配置与连接
Git使用ssh连接github,下载git后不需要再单独下载ssh软件,git内部集成ssh软件包。
1. 下载软件包Git-2.16.2-64-bit.exe

2. 安装软件到指定目录

3. 进入git-bash命令程序
执行以下命令:
cmd>git-bash.exe
进入命令行窗口,界面如下:

4. 生成公私密钥对
cmd>ssh-keygen -t rsa -C "xxx@xxx.com"
注意:-C后使用的是在github中注册时所用的email地址。
查看在home目录下生成公私秘钥文件
windows的主目录位于C:\user${当前用户}\.ssh下。
生成公私密钥对
cmd>ssh-keygen -t rsa -C "xxx@xxx.com"
【注意】-C后使用的是在github中注册时所用的email地址。
5. 查看在home目录下生成公私秘钥文件
windows的主目录位于C:\user${当前用户}\.ssh下。

6. 复制公钥文件内容到GitHub上
打开GitHub的公钥管理页面,如图所示:

定位到SSH and GPG keys条目,如下图所示:

点击new SSH Key按钮,如下图所示:

在文本框中粘贴生成公钥文件内容,输入title后,点击add SSH Key即可。如下图:

7. 在git-bash命令下测试是否能够ssh到github服务器
# 允许git-hbash命令行程序 cmd>git-bash.exe # ssh到远程github主机 $>ssh git@github.com
出现如下图信息,表示连接成功!

四、Git常用命令
1. 标签和分支
标签是一条分支上具有里程碑式的阶段划分,分支是两条不同的路线。一条主分支就是master分支,在开新功能时通常会创建新的分支,在新分支上进行开发,成熟后再合并到master主分支上去。
2. 本地仓库命令
仓库命令都是针对整个仓库进行的操作,因此命令后面不加文件等参数。
git init
该命令时在本地创建仓库目录后,进入目录下,将该目录初始化层仓库目录的过程。
# 创建目录 $>mkdir repo1 # 进入目录下 $>cd repo1 # 进行初始化处理 $>git init
git clone
克隆仓库是在首次使用远程仓库时,即本地没有仓库目录,从远程服务器下载整个仓库到本地文件系统中的初始化本地仓库过程。因此需要指定远程仓库的url地址,该地址可以在github的仓库主页上找到。url构成由域名构成如下:
https://github.com/{github注册账号}/{仓库名称}.git
以下命令就是下载oldboy-xupccc账号下的test1仓库到本地系统中:
# 进入本地仓库目录下(以下同) $git>cd localrepo $>git clone https://github.com/oldboy-xupccc/test1.git
git pull
pull命令是下载远程仓库内容到本地仓库,覆盖本地仓库的内容。
$>git pull
git push
push命令是将本地仓库上传到远程仓库,覆盖远程仓库的内容。
$>git push
3. 远程仓库命令
远程仓库命令是操纵github服务器上仓库资源的命令。在git remote组下。
package com.oldboy.umeng.spark
import com.oldboy.umeng.commom.util.ResourceUtil;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.function.ForeachPartitionFunction;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SparkSession;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.Iterator;
import java.util.List;
/**
*
*/
public class DayActiveStatService{
private static final string name = "tomas";
int age = 200;
public String getName(){
return name;
}
public static void main(String[] args){
//创建配置
SparkConf conf =new SparkConf();
conf.setAppName("stat");
conf.setMaster("local[4]");
//创建SparkSession
final SparkSession spark = SparkSession.builder().config(conf).enableHiveSupport().getOrCreate();
spark.sql("use big10_umeng").collect();
//注册临时函数
List funcs = ResourceUtil.loadResoureLines("register_temp_functions.sql");
for(String func : funcs){
spark.sql(func).collect();
}
//查询统计结果,入库
Dataset df = spark.sql(ResourceUtil.loadResoureString("stat_dayact.sql"));
//df.show(10000,false);
df.foreachPartition(new ForeachPartitionFunction(){
public void call(Iterator t) throws Exception{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://192.168.231.1:3306/big9";
String user = "root";
String pass = "root";
Connection conn = DriverManager.getConnection(url ,user ,pass);
conn.setAutoCommit(false);
//当前租户
String curr_tntid = "";
PreparedStatement ppst = null;
while(t.hasNext()){
Row row = t.next();
//提取租户
String tntid = row.getString(0);
//是否是同一租户
if(!tntid.equals(curr_tntid)){
//在mysql中准备该租户的统计表(日活)
String create_ddl = String.format(ResourceUtil.loadResoureString("create_dayact_ddl.sql"),tntid);
conn.createStatement().execute(create_ddl);
//insert into ....
String insertSQL = String.format(ResourceUtil.loadResoureString("insert_dayact.sql"),tntid);
ppst = conn.prepareStatement(insertSQL);
}
ppst.setString(1 , row.getString(1));
ppst.setString(2 , row.getString(2));
ppst.setString(3 , row.getString(3));
ppst.setString(4 , row.getString(4));
ppst.setString(5 , row.getString(5));
ppst.setString(6 , row.getString(6));
ppst.setLong(7, row.getLong(7));
ppst.executeUpdate();
}
conn.commit();
ppst.close();
conn.close();
}
});
}
}
(1032)