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提交记录详情

相关推荐
编程修仙9 小时前
github的使用
github
白驹过隙^^10 小时前
OB-USP-AGENT安装使用方法
数据库·经验分享·网络协议·tcp/ip·github·ssl
xlp666hub10 小时前
手写 Linux 并发服务器,fork, pthread与 epoll 模型实战(包含深层原理剖析)
github·c
sylvia_081511 小时前
git add 后pull 放弃本地所有修改
git
五阿哥永琪12 小时前
Git 开发常用命令速查手册
大数据·git·elasticsearch
火车叼位12 小时前
小白也能学会:AI分离人声 + FFmpeg替换音轨全流程
github
程序媛Dev12 小时前
平台工程新范式:我扔掉了本地环境,开发体验直接起飞。
github
柒壹漆12 小时前
用Python制作一个USB Hid设备数据收发测试工具
开发语言·git·python
逛逛GitHub13 小时前
这个 GitHub 神器让 Gemini 写的网站 3 秒上线,累计部署 67 万个网站。
github
GZKPeng13 小时前
github 新版本网页如何对repository管理人员
github