Git工作模式分析及远程仓库搭建

Git工作模式

目录

Git工作模式

Git初始化

Git基本命令

Github

Git原理

Git对象

远程仓库搭建


 

 

Git初始化

为每台电脑配置身份信息:

$ git config --global user.name "Your Name" $ git config --global user.email "email@example.com" 把某个目录变成可以让git管理到的目录(创建版本库) git init

Git基本命令

#把内容输入到一个文件 echo "xxxx" > xxxx #把工作空间的某个文件添加到cache git add xxxx #把工作空间的所有内容添加到cache git add -A #把cache当中的某个文件提交到本地库 git commit -m "xxxx" #all git commit -am "xxxx" #cache ---->work file恢复一个文件 file1 file2 恢复两个文件  .恢复所有文件 git checkout readme.txt #git状态查询 git status #查看不同的地方 默认查看工作区和cache #git diff --cached 比较cache和Repository #git diff HEAD 工作区和最新的Resository #git diff commit-id 工作区和制定的repository #git diff --cached commit-id #git diff --commit-id commit-id git diff #清除工作区的指定文件的修改 git checkout -- 文件名 #清除工作区所有文件修改 git checkout . #reset 回到之前的版本 ^一个表示一个版本 顾名思义 (HEAD~100) git reset HEAD^ #回退n个版本 git reset HEAD~n #git的日志 git log git log --pretty=oneline #oh my pretty pretty boy i love you git reflog 查看历史命令 #git rm --cached file_path git rm git mv #远程仓库的克隆岛本地库 git clone #关联远程仓库 git remote add github git@github.com:xxxxx git remote add centos7_vm1 root@192.168.195.3/home/git git clone root@192.168.195.3:/home/git #推送到远程仓库 git pusvue #如果没有关联远程分支 git push --set-upstream origin xxx #拉取远程仓库的内容 git pull #查看当前分支 -a查看所有分支 -av 查看所有分支的信息 -avv 查看所有分支的信息和关系 #-v 查看本地分支 #远程分支信息:./git/refs/remotes/origin/ 本地分支信息:./git/refs/heads/ git branch #创建一个分支 基于当前分支创建分支 git branch xxx #基于oldType创建分支 git branch newBranch oldType #切换分支 git checkout 分支的名字 #删除分支 git branch -d xxx #查看文件内容 git cat-file -p commitid #查看对象类型 blob commit tree git cat-file -t commitid

Github

$ ssh-keygen -t rsa -C "email" //public key for push git remote add nickName gitUrl // conn remote git push -u remoteBranch localBranch

分支

  • 查看分支
  • 创建分支

基于当前分支创积分分支 基于远程分支创建分支 基于新分支创建分支 基于提交创建分支 其实都是基于commit创建分支

  • 合并分支

一定要切换到被合并的分支上去合并

比如说A要合并A1

那么先要切换到A1,然后在A1上面执行merge

 

Git原理

find .get/objects -tpe f 查询objects下面所有文件 git cat-file -t 文件名文件hash值 查询文件类型 git cat-file -p 文件名文件hash值 反编译文件中的数据

 

Git对象

在.git/objects文件介绍,Git是通过objects中的文件进行文件管控

  • blob对象

存储的是文件内容(压缩的)。 文件名字是根据内容算出的一个hash值

  • tree对象

多个blob对象的引用 子tree对象 文件名 文件类型

  • commit对象

父commit 作者/提交者注释 指向一个tree的指针

 

图例:

git如何获取当前分支?

在.git下有个HEAD文件,文件内容就是当前分支信息:ref: refs/heads/xx

 

 

在.git/refs文件介绍,heads文件进行分支管控,文件中的数据是最近一次commit的ID

 

上图,相同的指针指向了不同文件,就是Git的精髓(不同分支一样的内容都会指向同一个blob文件)。

 

HEAD 为什么要通过 refs/heads/master 中转一下,而不是直接指向 master 分支的提交?

每个分支的头指针都指向该分支的最新提交 但是此时出现一个 dev 分支,刚从 master 检出,头指针和 master 相同,HEAD直接指向 提交的话,怎么知道,当前工作分支是 master 还是 dev 呢?

注:上面意思是,如果当前HEAD指向commitID,几个分支都是最新提交commitID相同,此时如果提交我们HEAD应该指向哪个分支?

但是会进入一种特殊的状态 detached HEAD。 detached HEAD,游离的 HEAD 指针。 使用 git checkout <commit id> 成功的进入了 detached HEAD 状态: 得出结论,当 HEAD 指针直接指向提交时,就会导致 detached HEAD 状态。在这个状态下, 如果创建了新提交,新提交不属于任何分支。相对应的,现存的所有分支也不会受 detached HEAD 状态提交的影响 example: 排查问题的时候,checkout 到怀疑的 commit 点上去做些测试,detached HEAD会保护你 的现有分支不受影响,测试完了不想保存直接 checkout 到其他地方,可以放弃修改。想保 存修改,可以创建一个 git checkout -b <new-branch-name> 新分支保存

 

远程仓库搭建

1.基于文件共享(nfs)

2.基于SSH搭建远程仓库

  • git init --bare 初始化空的Git版本库
  • git remote add centos7_vm1 root@192.168.195.3/home/git
  • git clone root@192.168.195.3:/home/git
  • git push centos7_vm1 master

3.搭建Gitlab

https://about.gitlab.com/installation/#centos-7

传上去gitlab-ce-10.8.2-ce.0.el7.x86_64.rpm

安装 rpm -ivh /home/tools/gitlab-ce-10.8.2-ce.0.el7.x86_64.rpm

sudo gitlab-ctl reconfigure 时间很少8-10分钟

 gitlab-ctl start 启动gitlab

访问gitlab http://ip:port

设置密码

 

QQ群号:464512055

群二维码:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值