git是一个开源的分布式版本控制系统,与SVN类似但是Git是分布式的,利于分支来操作管理代码,Git的操作一般使用命令,SVN操作一般倾向于可视化页面。
workspace:工作区
staging area:暂存区/缓存区
local repository:版本库或本地仓库
remote repository:远程仓库
Git 基本操作
拷贝一个 Git 仓库到本地:
git clone <地址>
实例:
//SSH
git clone git@gitee.com:Tony-Stark66/DepartmentManage_SpringBoot.git
//https
git clone https://gitee.com/Tony-Stark66/DepartmentManage_SpringBoot.git
分支:
// 分支相关
git branch
用于查看本地仓库分支和远程仓库分支
//切换本地分支
git checkout <本地分支名>
//切换本地分支,切换到master
git checkout master
// 新建并切换为login
git checkout -b login //新创建一个分支login
//合并分支
//将选中的分支合并到当前分支(是当前分支哦)
git merge <分支名>
//将login分支合并过来
git merge login
提交:
//初始化
git init
//添加当前目录下的所有文件到暂存区
git add .
//将暂存区内容添加到本地仓库中
git commit -m [message]
//添加远程版本库
git remote add [shortname] [url]
//删除与远程仓库之间的连接
git remote rm origin
//用于从将本地的分支版本上传到远程并合并
git push <本地分支名>|<远程分支名>
//用于从远程获取代码库。
git fetch
拉取远程仓库内容:
git pull <本地分支名>
用于从远程获取代码并合并本地的版本
提交项目之前要pull一下
报错处理:
1、执行 git add . 时报错
warning: LF will be replaced by CRLF in package.json.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in pnpm-lock.yaml.
The file will have its original line endings in your working directory
原因:
windows中的换行符为 CRLF,而在Linux下的换行符为LF,所以在执行git add . 时,会出现warning。
解决方法:
1、
git config core.autocrlf false //禁用自动转换