git基础
一.git概念
1.什么是git?
Git是一款免费、开源的分布式版本控制系统,广泛应用于软件开发领域。随着开源和云计算的发展,Git已经成为了开发者必备的工具之一。本文将为大家介绍Git在Windows、Mac和Linux三个平台上的安装和配置方法,带你一次性搞定Git环境
二.Git 安装
1.官网地址
https://git-scm.com/
2.淘宝镜像地址
https://npm.taobao.org/mirrors/git-for-windows/
下载之后无脑下一步安装即可,安装完毕就可以使用
3.git包讲解
Git Bash:Unix与Linux风格的命令行,使用最多,推荐最多
Git CMD:Windows风格的命令行
Git GUI:图形界面的Git,不建议初学者使用,尽量先熟悉常用命令Git 配置
三.Git 配置
1.查看git配置
$ git config -l
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=openssl
http.sslcainfo=D:/APP/git/Git/mingw64/ssl/certs/ca-bundle.crt
core.autocrlf=true
core.fscache=true
core.symlinks=false
core.editor="D:\\APP\\notepad++\\notepad++.exe" -multiInst -notabbar -nosession -noPlugin
credential.helper=manager
2.查看系统的配置
$ git config --system --list
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=openssl
http.sslcainfo=D:/APP/git/Git/mingw64/ssl/certs/ca-bundle.crt
core.autocrlf=true
core.fscache=true
core.symlinks=false
core.editor="D:\\APP\\notepad++\\notepad++.exe" -multiInst -notabbar -nosession -noPlugin
credential.helper=manager
#相关配置文件位置
D:\APP\git\Git\etc\gitconfig
3.查看本地的配置
$ git config --global --list
user.name=用户名
user.email=邮箱
#相关配置文件路径
C:\Users\user\.gitconfig
4.配置个人的用户名称和电子邮件地址:
git config --global user.name "用户名"
git config --global user.email 邮箱地址
四.Git 理论
1.基本概念
- 工作区:平时存放项目代码的地方。
- **暂存区(Stage/Index):**暂存区,用于临时存放你的改动,事实上它只是一个文件,保存即将提交到文件列 表信息
- **版本库:**又称本地仓库,这个不算工作区,而是 Git 的版本库,里面有你提交到所有版本的数据。
- 远程仓库:托管代码的服务器
2.工作流程
1、在工作目录中添加、修改文件;file
2、将需要进行版本管理的文件放入暂存区域;git add
3、将暂存区域的文件提交到git仓库。git commit
3.Git 基本操作
创建本地仓库的方法有两种:
- 创建新的仓库。
- 克隆远程仓库。
1.创建一个新的仓库
# 使用当前目录作为 Git 仓库,我们只需使它初始化。
git init
$ git init
Initialized empty Git repository in C:/Users/user/Desktop/git_init/.git/
该命令执行完后会在当前目录生成一个 .git 目录。
2.克隆远程仓库项目,相当于SVN导出项目
git clone <url>
git clone 仓库地址
3.查看文件状态
git status filename
4.加入到缓存区
git add .
5.提交到本地
git commit -m "说明"
五.使用Gitee
官网:https://gitee.com/
1.创建自己仓库
2.拉取远程创库
git clone 仓库地址
3.添加需要的文件
4.加入缓存区
git add [filename]
5.提交到本地
git commit -m "说明"
6.发布到远程仓库
git push
六.分支
可以理解多线程:主线程在走,不影响子影响。它们是平行,互不影响。但是,他们可以进行合并。在合并的时候就需要做一些处理了。
1.git分支中常用指令
# 列出所有本地分支
git branch
# 列出所有远程分支
git branch -r
# 新建一个分支,但依然停留在当前分支
git branch [branch-name]
# 新建一个分支,并切换到该分支
git checkout -b [branch]
# 合并指定分支到当前分支
$ git merge [branch]
# 删除分支
$ git branch -d [branch-name]
# 删除远程分支
$ git push origin --delete [branch-name]
$ git branch -dr [remote/branch]