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
相关推荐
K3v30 分钟前
【git】删除本地以及远端已经合并到master的分支
大数据·git·elasticsearch
云攀登者-望正茂5 小时前
将 develop 分支拉取到特性分支时解决合并污染问题
git
金銀銅鐵7 小时前
[git] 如何找到已经“丢失”的 commit?
git·后端
尘世壹俗人7 小时前
linux编译安装git
linux·运维·git
打不了嗝 ᥬ᭄1 天前
Git 原理与使用
git·gitee
m0_614619061 天前
花了一下午学 Git,整理了一份学习笔记
笔记·git·学习
AGV算法笔记1 天前
解决Git> git add -A -- fatal: CRLF would be replaced by LF in Test/Test.cpp
git
Dontla1 天前
VSCode插件Git Graph介绍(Git可视化管理分支、可视化Git)
ide·git·vscode
Echoo华地1 天前
用git diff快速比较文件夹差异并生成报告
linux·git·unix·repository·diff·branch
勤劳打代码1 天前
防微杜渐 —— 为什么一次 Sync 会变成一次 merge?
git·团队管理