git操作

首先需要有gitbash

在gitbash中,cd想要上传的文件目录,需要用\

bash 复制代码
cd E:\\bupt\\20250630aic\\code
git init
git add DataGenerate/ (文件夹名)
git commit -m 'version 1' (注释)
git remote add origin  https://github.com/sylviiiiiia/line_chart_generation.git (add一个叫origin的远程)
git pull --rebase origin main (远程仓库里main的分支)
git push origin main(首次推送并建立跟踪关系)

如果最后报错

bash 复制代码
hint: Updates were rejected because the remote contains work that you do not
hint: have locally. This is usually caused by another repository pushing to
hint: the same ref. If you want to integrate the remote changes, use
hint: 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

是因为远程仓库已经存在内容(比如 README、LICENSE 或 .gitignore),而本地没有这些提交,所以 Git 拒绝直接覆盖。

强制覆盖:

bash 复制代码
git push -f origin main

或者先把远程的改动拉下来合并,再推送

bash 复制代码
# 拉取远程 main 并自动与本地的 main 做合并
git pull origin main --rebase

# 如果没有冲突,直接推送
git push -u origin main

成功后确认

bash 复制代码
git log --oneline -5
相关推荐
vistaup4 小时前
windows git 更新当前目录下所有的文件(非递归)
windows·git
王码码20354 小时前
Flutter for OpenHarmony:Flutter 三方库 algoliasearch 毫秒级云端搜索体验(云原生搜索引擎)
android·前端·git·flutter·搜索引擎·云原生·harmonyos
Irene19918 小时前
Git 命令汇总表(基于一次完整的 Git 实战经验整理,涵盖从安装配置到日常开发、问题排查的所有常用命令)
git·常用命令
q5431470879 小时前
Redis Desktop Manager(Redis可视化工具)安装及使用详细教程
redis·git·bootstrap
素雨迁喜10 小时前
Linux平台下git工具的使用
linux·运维·git
Irene199112 小时前
Windows环境,VS Code 中 Git 配置指南
git·基础配置
Yang-Never13 小时前
AI Code -> Windows电脑安装Claude
开发语言·windows·git
Irene199113 小时前
2026 前端开发 Windows 安装 Git 配置指南(有实际安装过程参考:适配版本 the latest 2.53.0(2) x64 )
前端·windows·git
早起的年轻人14 小时前
告别Git仓库臃肿:一招解决Maven target目录误提交问题
java·git·maven
悠然大月季1 天前
git 怎么导出提交历史,文件是乱码
git·git导出历史记录·git导出历史乱码