git命令与常见错误解析

发布时间 2023-05-31 17:41:42作者: 菜鸟C_5022

最好在根目录下一级一级的探索添加 尽量避免 git add . git rm -r --cache . 等全部上传和移除操作

git命令

创建本地代码库(只执行一次) 若有多个.git则会出现ERROR: 500
git init

查看工作区状态
git status (分支:开发版、测试版、发布版)

添加文件到缓存区
git add<修改的文件>
eg:git add 1.cpp添加 git rm --cache 1.cpp移除 git add . 全部添加 git rm *.后缀

​ git rm -r --cache . 删除本地所有缓存信息,用于重新上传

提交修改
git commit -m "文件描述"
git log 查看提交日志

提交规范:

【项目:COM组件练习】【ones:3】【改动:xxxxxxxxxxxxx】

git远程仓库指令

上传: git push

添加 / 删除

git remote add / remove

git remote add origin https://xxxxxxxxxxxxxxxxxxx

git push -u origin master

​ origin可以理解为上传地址的赋值变量 master 上传的分支

​ 若发现本地和云端的信息不一致 重新删除本地缓存并上传 git rm -r --cache .

查看远程代码 git remote -v

拉代码
克隆远程仓库: git clone https://xxxxxxxxxxxxxxxxxxxxx
向服务器远程访问 git remote show origin

​ 云端和本地不一致,需要拉取 git pull .

git上传流程 & 错误代码及解决

在一个新的文件夹里 git init创建.git缓存目录 (只一次)

保证用户名和邮箱与git.cn中一致

git config --global user.name "wangjie_2"
git config --global user.email wj5022@qq.com

纯文本文件.gitignore与.git文件在同级目录下,过滤规则为
.vs
Debug/
*.user

git add . 添加所有文件到缓存目录中

git rm -r --cache . 删除本地所有缓存信息,用于重新上传,再重新 git add .

git status 查看缓存目录中文件状态

git commit -m "【项目:删除数组元素】【ones: 1】【改动:第一次上传】" 添加注释信息

git remote add origin https://git.wpsit.cn/hubu-2023-cpp-tasks/wangjie_2.git 远程连接

git push -u origin master 上传

其他命令

git config --list 查看信息

git clone https://url 克隆代码

git log 查看提交历史

错误信息1:

! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://git.wpsit.cn/hubu-2023-cpp-tasks/wangjie_2.git'

主要原因是gitee中的README.md文件不在本地代码目录中

输入 git pull --rebase origin master 命令将README.md拉到本地,

git push -u origin master上传

错误信息2:

HTTP 413 curl 22 The requested URL returned error: 413 Request Entity Too Large

错误原因:http的413错误码是请求体太大,gitignore未发挥作用

错误信息3:

各个操作系统换行不一样造成的

输入git config core.autocrlf false

将core.autocrlf配置为false,即不开启自动转换功能。

warning: LF will be replaced by CRLF in .idea/compiler.xml. The file will have its original line end

exe文件打包

可参考文档:

(47条消息) VS2019下打包QT项目的方法(包含第三方库)_vs2019应用程序打包项目_864306337的博客-CSDN博客

(47条消息) QT | QT5.12.0程序打包_qt5 打包_热爱生活的小润的博客-CSDN博客

[(47条消息) QT | Cannot find Visual Studio installation directory,VCINSTALLDIR is not set_热爱生活的小润的博客-CSDN博客](https://blog.csdn.net/qq_43466146/article/details/125278458?ops_request_misc=&request_id=&biz_id=102&utm_term=Warning: Cannot find Visual St&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduweb~default-0-125278458.142v87control_2,239v2insert_chatgpt&spm=1018.2226.3001.4187)

系统变量->“新建”,填写变量名为VCINSTALLDIR,变量值VS中的VC文件夹所在位置,

1、找到exe文件复制到一个新的文件夹,得到这个文件夹的路径

2、找到D:\Qt\Qt5.9.3\5.9.3\msvc2017_64\bin 下的 windeployqt ,需要这个路径

3、打开cmd 进入到上面的 windeployqt 路径,输入命令 windeployqt 新建的.exe文件夹路径,如:windeployqt C:\Users\WangJ\Desktop\Exec\myModel.exe