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
相关推荐
m0_5791466513 小时前
已被 Git 追踪的本地修改文件如何实现临时忽略
git
糖少主16 小时前
WSL中使用Beyond Compare 3/4/5作为difftool
git·wsl·beyond compare·difftool
console.log('npc')18 小时前
Git版本管控:git reset \+ git push \-f 原理、实操与避坑指南
git
恋喵大鲤鱼1 天前
git reflog
git·git reflog
MatrixOrigin1 天前
MatrixOne Git4Data 技术详解(二):从零跑通所有 Git 原语
git
anew___1 天前
常用的 Git 工作流
git
shimly1234561 天前
git diff 生成一部分文件的补丁
git
m0_579146651 天前
Git 重置模式详解:四种重置方式的原理与应用场景
git
恋喵大鲤鱼1 天前
git grep
git·git grep
霸王龙的小胳膊1 天前
Git基础知识
git