Git操作与异常处理

文章目录

在日常的开发中,对代码的git管理,各种操作记录下来,方便备查。

常用操作

1、代码拉取

powershell 复制代码
// 从远程仓库拉取代码
git pull

2、代码提交

powershell 复制代码
// 代码提交暂存区
git add .

3、暂存区状态

查看暂存区中是否有未提交的diam

powershell 复制代码
//暂存区
git status

4、提交代码

powershell 复制代码
//暂存区
git commit -m 'commit code'

5、推送远程仓库

powershell 复制代码
// 推送仓库
git push

异常处理

【1】报错信息:Cannot pull into a repository with state: MERGING

处理方案

尝试先提交现有代码到本地,再更新

powershell 复制代码
// 推送仓库
git reset ---hard

【2】报错信息:You have not concluded your merge (MERGE_HEAD exists)

处理方案

尚未合并的 MERGE_HEAD 存在,请在合并前提交你的修改

powershell 复制代码
// 终止合并
git merge --abort
// 重置合并
git reset --merge
// 重新拉取代码
git pull

【3】报错信息:git warning: LF will be replaced by CRLF in

处理方案

windows中的换行符为 CRLF, 而在Linux下的换行符为LF,所以在执行add . 时会出现

powershell 复制代码
// 设置格式
git config core.autocrlf false

日常问题

【1】端口占用

处理方案:

第一步、根据提示信息,查看端口情况

powershell 复制代码
// 查看8080端口
netstat -ano | findstr 8080

查看结果如下,找到其父PID,本次是 3952。

第二步、杀死父进程

taskkill 命令杀死进程,重新查看端口,则发现8080端口已经被杀死。

powershell 复制代码
// 杀死进程
taskkill /F /PID 3952
相关推荐
l1x1n022 分钟前
Vim 编辑器常用操作详解(新手快速上手指南)
linux·编辑器·vim
jingshaoqi_ccc2 小时前
GitKraken最后一个免费版本和下载地址
git·github·gitkraken·版本管理工具
乌云暮年2 小时前
Git简单命令
git·gitee·github·batch命令
用户1259265423205 小时前
使用 Docker 搭建 Gitea 并实现 Git HTTP 自动登录
git
一只毛驴7 小时前
谈谈对git stash的理解?
git
Shan12058 小时前
编辑器Vim的快速入门
linux·编辑器·vim
通信小小昕10 小时前
ubuntu18.04.1无法安装vscode(安装依赖无效)
ide·vscode·编辑器
长风破浪会有时呀12 小时前
Git 学习笔记
笔记·git·学习
ykjhr_3d15 小时前
华锐云空间展销编辑器:开启数字化展示新时代
编辑器
许白掰15 小时前
Linux入门篇学习——Linux 工具之 make 工具和 makefile 文件
linux·运维·服务器·前端·学习·编辑器