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
相关推荐
关于不上作者榜就原神启动那件事1 小时前
git版本控制学习
git·学习
Cchaofan8 小时前
Git/GitLab日常使用的命令指南来了!
git·gitlab
2301_8035545210 小时前
vim,gcc/g++,makefile,cmake
linux·编辑器·vim
ykjhr_3d13 小时前
解锁课程编辑器之独特风姿
编辑器
threelab14 小时前
12.three官方示例+编辑器+AI快速学习webgl_buffergeometry_indexed
学习·编辑器·webgl
MonkeyKing_sunyuhua14 小时前
在 Visual Studio Code (VSCode) 中配置 MCP(Model Context Protocol)
ide·vscode·编辑器
可乐加.糖15 小时前
项目版本管理和Git分支管理方案
java·git·目标跟踪·gitlab·敏捷流程·源代码管理
wingaso15 小时前
[经验总结]删除gitlab仓库分支报错:错误:无法推送一些引用到“http:”
linux·数据仓库·git
小妖66618 小时前
VScode 的插件本地更改后怎么生效
ide·vscode·编辑器
MonkeyKing_sunyuhua20 小时前
ubuntu22.04卸载vscode
ide·vscode·编辑器