目录
一、前置准备
二、git简介
三、gitee.com的基本使用
1.创建仓库(私库和公库)
?2.创建文件及文件夹
?新建文件夹两种方式
①?
?②
?3.删除
删除文件
?删除仓库
四、组长组员的git使用?
git clone
?查看文件
?git status
??git add?
?git commit
??git push
? ?## 命令行配置
多个添加
?git reset HEAD
?git pull
?git init
?上传到码云(gitee.com)
五、git冲突
一、前置准备
1.申请并[激活]一个Gitee帐号 ? 2.在window中安装Git ? ? ?版本要求:Git-2.22.0-64-bit.exe或以上版本, ? ? ?安装路径:请不要安装在C盘(win10会有权限问题),建议选择“D:\tools\Git”


二、git简介
Git是什么? ? ?Git是一个开源的[分布式][版本控制系统],用于敏捷高效地处理任何或小或大的项目
版本控制器 ? ?CVS/SVN/Git
Git与SVN区别 ? 2.1 去中心化 ? ? ? GIT是分布式的,SVN不是:这是GIT和其它非分布式的版本控制系统,例如SVN,CVS等,最核心的区别。 ? ?? ? 2.2 git仓库的任何一个拷贝都可以独立作为一个服务器来使用 ? 2.3 在Git中文件有四种状态: ? ? ? 未跟踪(untrack):表示文件为新增加的 ? ? ? 已修改(modified):表示修改了文件,但还没保存到git仓库中。 ? ? ? 已暂存(staged):表示对一个已修改文件的当前版本做了标记,使之包含在下次提交的快照中 ? ? ? 已提交(committed):表示文件已保存在git仓库中。 ? 2.4 其它 ? ? ? GIT没有一个全局的版本号,而SVN有:目前为止这是跟SVN相比GIT缺少的最大的一个特征。 ? ? ? GIT的内容完整性要优于SVN:GIT的内容存储使用的是SHA-1哈希算法。这能确保代码内容的完整性,确保在遇到磁盘故障和网络问题时降低对版本库的破坏 ? 2.5 直接记录快照,而非差异 ? ? ? GIT把内容按元数据方式存储,而SVN是按文件:所有的资源控制系统都是把文件的元信息隐藏在一个类似.svn,.cvs等的文件夹里。 ? ? ? 直接记录快照,而非差异 ? 2.6 直接记录快照,而非差异 ? ? ? GIT分支和SVN的分支不同,分支在SVN中一点不特别,就是版本库中的另外的一个目录。 ? 2.7 git存在分支

三、gitee.com的基本使用
1.创建仓库(私库和公库)

?

?
?创建成功 此时是私库
?改成开源即是公库 滑到管理的地方

?选择开源
?2.创建文件及文件夹


?
?新建文件夹两种方式
①
?
?②

?3.删除
删除文件

?删除仓库
点击仓库名-->管理-->删除仓库-->输入要删除的仓库名-->输入密码确认删除


?
?
?
四、组长组员的git使用?
准备工作:
新建一个仓库cdl-a
改成公有的
创建一个文件Goods
常用命令(重点) ? ?git clone :将远程仓库clone到本地计算机。 ? ?git status :展示工作区及暂存区域中不同状态的文件。 ? ?git add :将内容从工作目录添加到暂存区。 ? ?git commit :所有通过 git add 暂存的文件提交到本地仓库。 ? ?git push :将本地仓库的记录提交到远程仓库。 ? ?git reset HEAD <file> :从暂存区移除指定文件。 ? ?git pull :拉取远程仓库的数据。
git clone
在本地新建一个文件夹

?右键

?出现黑窗口

?
完整命令

?回车 成功加载到本地

?查看文件

?
?git status
展示工作区及暂存区域中不同状态的文件
表示该文件为新添加的

??git add?
将内容从工作目录添加到暂存区。

?git commit
所有通过 git add 暂存的文件提交到本地仓库

?
??git push
将本地仓库的记录提交到远程仓库

?
?
?本地电脑:
? ?代码区:工作区间,放代码的地方
? ?暂存区:git所管理的暂存区域
? ?本地仓库:git在本地所管理的硬盘区
远程电脑:
? ?远程仓库:github,gitee
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?git add? ? ? ?git commit? ? git push
? ?代码提交过程:代码区-->暂存区-->本地仓库-->远程仓库
? ?代码区-->暂存区-->本地仓库 不需要联网
????本地仓库-->远程仓库 需要联网??
? ?## 命令行配置
? ?0.“Git bash here”打开命令窗口 ? ?1.查看git的配置列表 ? ? ?git config --list ? ? ?注1:如果没有配置东西,应该是空的。照着下面步骤配置完成后,你可以再试一下该命令,就会出现一系列配置信息 ? ?2.设置用户名/邮箱/密码 ? ? ?git config --global user.name "username" ? ? ?git config --global user.email "email" ? ? ?git config --global user.password "password"
多个添加
本地添加几个文件

?
?

安全性降低
?git reset HEAD <file>
从暂存区移除指定文件

?git pull
拉取远程仓库的数据。
此时假设组长对上传的文件进行改变

?
?
?没有所删除的文件
?
?git init
新建一个项目(文件夹)

?上传到码云(gitee.com)
新建一个空的仓库,并且设置开源
将本地仓库和远程仓库进行关联
?初始化前有画黄线的命令


?失败的原因:github本身进行的改变
要在执行改命令前进行本地仓库与远程仓库的同步,实现远程与本地代码的合并git pull --rebase origin master


注意:空的文件夹上传不了
组长:
? 1.在某一个工作区间搭建环境,ssm能跑起来
? 2.在该工作区间中执行git init 命令,标记该工作区间由git所管理
? 3.在gitee/github中新建仓库
? 4.通过git remote add origin url 将本地仓库与远程仓库关联
? 5.将本地仓库与远程仓库进行文件同步
? 6.执行git三部曲 add commit push 将搭建好的环境推送到远程仓库
组员:
?1:通过git clone将组长搭建好的环境克隆到本地,并且保证项目能运行
?2.测试组员修改/新增代码是能够推送到远程仓库的
? ? 测试git add/commit/push是否有用
五、git冲突
Git冲突与解决方法 ? ? ?1.git冲突的场景(课程中主要演示情景三) ? ? ?情景一:多个分支代码合并到一个分支时; ? ? ?情景二:多个分支向同一个远端分支推送代码时; ? ? ?情景三:同一分支,同一文件修改后的提交(即为多个程序员修改了同一个文件) ? ? ?实际上,push操作和pull操作其实就分别是用本地分支合并到远程分支 和 将远程分支合并到本地分支,所以这两个过程中也可能存在冲突。 ?? ? ?分别在同一项目的两个不同本地仓库修改a.txt并提交,则会报出以下错误: ? ?! [rejected] master -> master (fetch first) error: failed to push some refs to ' 。。。'
? ?拒绝 ? ?错误:无法推送某些引用?
? ?解决方案: ? ?1.将代码copy出来 ? ?2.先从远程仓库pull代码至本地,再修改冲突代码, ? ? ?? ? ? ?注1:git status查看仓库状态,会显示红色的错误提示消息“ both modified: ? a.txt” ? ?3.打开a.txt,手动修改冲突部分的代码 ? ? ?<<<<<<< HEAD ? ? ?ww add 18:42 from e:\temp\test1 ? ? ?=======
? ? ?ls add 123 at 18:17 from d:\temp\test1 ? ? ?>>>>>>> 63c73e5933bb7d3d2bed04b06c37a74602d65b2e ? ? ?注1:<<<<<<< HEAD ?>>>>>>>之间的即为冲突的代码,手动修改即可 ? ? ?? ? ?3.依次add/commit/push代码至远程仓库 ? ? ?commit执行完生,重新查看仓库状态git status,红色的错误提示消息“ both modified: ? a.txt” ? ? ?已经没有,表示冲突已解决 ?
?
|