GIT是什么
GIT是一种分布式版本控制工具。GIT是通过快照的方式管理文件的版本,即GIT保存了文件的所有版本,进而用户可以返回到如何操作前的版本。比如你不小心将一些GIT中的重要文件(非GIT的配置文件)删除了,你可以使用GIT回滚到删除前,就和没有删除一样,但是GIT会进行记录。
GIT和SVN的区别
管理方式的不同
GIT是通过快照的方式来管理文件,而SVN是通过增量式来管理文件。增量式是一种记录用户对文件修改的那个部分,不会记录文件重复的那个部分。当调用程序时,SVN会将原文件会修改部分叠加起来,组成最终的程序。
权限管理的不同
SVN是不允许不是同一个组的开发者修改代码。GIT允许不是同一个组的开发者修改代码,但是需要程序的拥有者审核同意后才能真正修改程序的代码。
版本控制的不同
GIT是分布式控制工具,而SVN是集中式控制工具。其管理方式如图


可以看的出来分布式的数据会比较安全,因为每个用户都有该项目的完整信息,如果有个用户的数据丢失了,可以利用别的用户来恢复。但是集中式需要确保服务器一直保持正常工作,不能出错,不然的话,数据就有可能丢失。
优势
大部分操作是在本地完成,不需要联网
保证上传信息的完整性
版本迭代通常采用增加版本,而不是删除或替代
分支操作流畅
兼容linux
GIT的结构

GIT基本命令
初始化
命令:
git init

效果:

设置签名:
签名的作用:
只用于区分用户的身份,用户名和Email可以和GitHub上注册的不一样,Email可以是无效的.
项目级别/仓库级别:
仅在当前本地库范围内有效.
命令
git config user.name 用户名
git config user.email email
系统用户级别:
在整个操作系统范围内有效.
命令
git config --global user.name 用户名
git config --global user.email email
级别优先级
就近原则:当有两种签名时,优先使用项目级别
如果只有系统用户级别的签名,就以系统用户级别的签名为准
不存在两者都不存在
状态查看
命令
git status (查看工作区和暂存区的情况)
效果

添加
命令
git add 文件名
效果

提交
命令
git commit 文件名
效果


查看历史记录
命令
git log 显示详细信息

git log --pretty=oneline

git log --oneline

git reflog

显示版本所需移动的信息
版本的移动
本质
HEAD是一个指针,所以版本的移动本质是移动HEAD指针
命令
git reset --hard 局部索引值
git reset --hard HEAD^ (只能后退,有几个^就后退几步)
git reset --hard HEAD~数字 (数字表示后退几个版本)
效果


删除文件并找回
本质
版本的回溯,所以只能返回到提交文件到本地库的那个状态.如果没有提交,就不能恢复.
命令
git reset --hard 局部索引值(找删除前的版本即可)
比较文件的差异
命令
git diff 文件名(默认和暂存区进行比较)

git diff 本地库历史版本 文件名

git diff (比较所有文件的差异)

分枝管理
什么是分枝
在版本迭代中,使用多用户同时推进版本的更新。
分枝的好处
同时开发,提高效率
各个分枝在开发过程中是相对独立的,如果一个分枝开发失败(并不会影响别的分枝),可以克隆一份别的分枝,继续开发。
命令
创建分支:
git branch 分支名
查看分枝
git branch -v
切换分枝
git checkout 分枝名

合并分枝
步骤:
第一步:切换到需要更新内容的分支上(git checkout 分枝)
第二步:执行git merge 有新内容的分支名
冲突的解决
第一步:与版本冲突的开发人员协商,并修改文件(包括删除git新增符号)
第二步:git add 文件名
第三步:git commit -m "修改信息"


来源:https://www.cnblogs.com/whllow/p/12195231.html