git add和git commit了大文件导致上传不到github的撤销操作

撤销git add和git commit操作(对于修改过的代码无影响)

python 复制代码
git reset HEAD^ 

HEAD^代表撤销最近的一个,如果有多个就reset多几次

参考:git commit之后,撤销commit提交,却保留代码

然后需要设置.gitignore文件来忽略掉大文件后重新git add 和git commit

  • .gitignore 文件的格式是每行一个文件路径或文件模式,可以使用通配符进行匹配。以下是一些常见的例子:

忽略某个特定文件:

python 复制代码
largefile.zip

忽略某个文件夹及其内容:

python 复制代码
/largefolder/

忽略特定类型的文件(例如 .mp4 或 .log 文件):

python 复制代码
*.mp4
*.log

忽略所有 .tmp 文件:

python 复制代码
*.tmp

忽略某个特定的子目录中的文件:

python 复制代码
/path/to/largefile/

在 .gitignore 配置好之后,你可以使用 git status 来确认文件是否被正确忽略。如果文件已被添加到 Git 跟踪中(即已被提交或暂存),Git 仍然会继续跟踪它们,即使你把它们添加到 .gitignore 中。为此,你需要执行以下操作:如果文件已经被 git add,但你想让它被 .gitignore 忽略,可以使用:

python 复制代码
git rm --cached .

重新trace file

python 复制代码
git add ./*

然后再git commit和git push就可以了

python 复制代码
git commit -m "注释"
python 复制代码
git push origin master

参考:
git 修改.gitignore后生效
git查看commit提交记录详情

相关推荐
无限进步_7 小时前
【C++】大数相加算法详解:从字符串加法到内存布局的思考
开发语言·c++·windows·git·算法·github·visual studio
IT WorryFree10 小时前
Git for Windows v2.52.0 发布说明
windows·git
烟锁池塘柳011 小时前
GitHub 强制回退版本并覆盖远程仓库
git·github
Maggie_ssss_supp14 小时前
Linux-MySQL主从复制
github
css趣多多14 小时前
git的基本使用
git
秋月的私语15 小时前
Windows系统下Git换行符问题的完整解决方案
windows·git
cg501716 小时前
Continue插件实现本地部署一个“cursor”或“github copilot”
github·copilot·curcor
兰舟比特16 小时前
【Git专栏】Git中常用撤回add和commit的指令
git
妙娲种子16 小时前
gittee连接github镜像
gitee·github
无限进步_17 小时前
C语言实现贪吃蛇游戏完整教程【最终版】
c语言·开发语言·c++·git·游戏·github·visual studio