git 项目的更新
更新项目
当自己的本地项目与 远程的github 的仓库已经建立远程连接时, 则直接按照下面的步骤,
将本地的项目代码更新到远程仓库。
# Stage the resolved file
git add README.md <file1> <file2># To stage all changes:
git add .# Commit the merge
git commit -m "Resolved merge conflict in README.md"# Push the changes
git push origin main
如果在此之前, 自己的本地仓库并没有与远程的仓库建立连接时, 则先需要按照下面的步骤进行连接建立。
1. 建立连接
由于github在 2021 年开始, 取消使用密码登录的方式, 因此 这里推荐使用第二种 通过ssh 连接的方式,进行登录。
The error occurs because GitHub no longer supports password-based authentication for HTTPS URLs (as of August 13, 2021). Instead, you need to use one of the following authentication methods:
Option 1: Use a Personal Access Token (PAT)
GitHub now requires a Personal Access Token (PAT) instead of a password for HTTPS authentication.
Steps:
-
Generate a PAT:
- Go to your GitHub account settings: GitHub Tokens.
- Click Generate new token.
- Select the appropriate scopes (e.g.,
repofor full control of private repositories). - Generate the token and copy it (you won’t be able to see it again).
-
Use the PAT for Authentication:
- When prompted for a password, paste the PAT instead of your GitHub password.
Example:
Username for 'https://github.com': your_account Password for 'https://xxxxx@github.com': <paste-your-PAT-here>
Option 2: Use SSH Authentication
SSH is a more secure and convenient way to authenticate with GitHub.
Steps:
- Generate an SSH Key (if you don’t already have one):
- Run the following command in your terminal:
ssh-keygen -t ed25519 -C "your_email@example.com" - Press Enter to accept the default file location and passphrase (optional).
- Run the following command in your terminal:
The command ssh-keygen -t ed25519 -C "your_email@example.com" is used to generate a new SSH key pair for secure authentication with remote servers, such as GitHub. Let’s break down the command and its components:
Command Breakdown
-
ssh-keygen:- This is the command-line tool used to generate, manage, and convert SSH keys.
-
-t ed25519:- The
-tflag specifies the type of key to generate. ed25519is a cryptographic algorithm used to create the key pair. It is a modern, secure, and efficient algorithm based on elliptic curve cryptography.- You can replace
ed25519with other algorithms, such as:rsa: Older but widely supported algorithm (e.g.,-t rsa -b 4096generates a 4096-bit RSA key).ecdsa: Elliptic Curve Digital Signature Algorithm (e.g.,-t ecdsa -b 521generates a 521-bit ECDSA key).dsa: Older and less secure (not recommended).
- The
-
-C "your_email@example.com":- The
-Cflag adds a comment to the key, which is typically your email address or a label to help identify the key. - This comment is embedded in the public key file and is useful for keeping track of which key is associated with which account or purpose.
- The
Why Use Different Algorithms (-t Options)?
You can use different algorithms (ed25519, rsa, ecdsa, etc.) for different repositories or purposes, but this is not common practice. Instead, people usually generate one key per machine or purpose and reuse it across multiple repositories. However, here are some reasons you might use different algorithms:
-
Compatibility:
- Some older systems or services may not support modern algorithms like
ed25519. In such cases, you might need to usersaorecdsa.
- Some older systems or services may not support modern algorithms like
-
Security Requirements:
- If you have specific security requirements, you might choose an algorithm based on its strength or performance characteristics.
-
Organizational Policies:
- Some organizations enforce specific key types for compliance or standardization.
How to Use Different Keys for Different Repositories
If you want to use different SSH keys for different repositories, you don’t need to generate keys with different algorithms. Instead, you can:
- Generate multiple SSH key pairs (e.g., one for work and one for personal use).
- Add the keys to your SSH agent.
- Configure your SSH client to use the appropriate key for each repository using the
~/.ssh/configfile.
Summary
- The command
ssh-keygen -t ed25519 -C "your_email@example.com"generates a secure SSH key pair using theed25519algorithm. - You can use different algorithms (
-toptions) for compatibility or specific requirements, but it’s not necessary for managing multiple repositories. - To use different keys for different repositories, generate multiple keys and configure them in your
~/.ssh/configfile.
Let me know if you need further clarification!
-
Add the SSH Key to Your GitHub Account:
- Copy the public key to your clipboard:
cat ~/.ssh/id_ed25519.pub - Go to your GitHub account settings: GitHub SSH Keys.
- Click New SSH key, give it a title, and paste the public key.
- Copy the public key to your clipboard:
-
Change the Remote URL to SSH:
这里注意 使用的 git@github.com
- Update your remote repository URL to use SSH instead of HTTPS:
git remote set-url origin git@github.com:xxxx_name/respitory.git
这里需要注意, 你远程的仓库 使用的是main 还是 master.
- Now you can push without entering a username or password:
git push origin main
Option 3: Use GitHub CLI
If you have the GitHub CLI installed, you can authenticate using the gh command.
Steps:
- Install the GitHub CLI: GitHub CLI Installation.
- Authenticate with GitHub:
gh auth login - Follow the prompts to log in and authorize the CLI.
Option 4: Use a Credential Helper
You can configure Git to remember your credentials.
Steps:
- Enable the credential helper:
git config --global credential.helper store - Push your changes. The first time, you’ll be prompted for your username and PAT. After that, Git will remember your credentials.
Summary
- Recommended: Use a Personal Access Token (PAT) or switch to SSH for authentication.
- If you’re unsure, start with the PAT method.
2. 处理冲突
当远程仓库和本地仓库发生冲突时, 需要先解决冲突
我们正常更新时的状态是, 远程仓库的文件在本地是具有的,
而如果远程的文件在本地中不存在时, push 时就会存在冲突, 此时需要先需要拉取远程中的文件,然后,根据自己的选择,进行更新或者更改, 之后在推送。
The error indicates that the remote repository has changes that you don’t have locally, and Git is preventing you from overwriting those changes. To resolve this, you need to pull the remote changes first, merge them with your local changes, and then push your updates.
Steps to Fix the Issue:
-
Pull the Remote Changes:
Run the following command to fetch and merge the remote changes into your local branch:git pull origin main- If you’re using SSH, it will look like this:
git pull origin main - If you’re using HTTPS, it will prompt you for your GitHub username and Personal Access Token (PAT).
- If you’re using SSH, it will look like this:
-
Resolve Conflicts (if any):
- If there are merge conflicts, Git will notify you. Open the conflicting files, resolve the conflicts, and save the changes.
- After resolving conflicts, stage the resolved files:
git add <file1> <file2>
-
Commit the Merge:
If there were conflicts, commit the merge:git commit -m "Merge remote changes into local branch" -
Push Your Changes:
Once the remote changes are merged with your local changes, push your updates:git push origin main
Optional: Force Push (Not Recommended)
If you’re sure you want to overwrite the remote changes (e.g., if you’re working alone and don’t care about the remote changes), you can force push:
git push --force origin main
Warning: Force pushing can overwrite remote changes, so use it with caution, especially in collaborative environments.
Summary of Commands:
git pull origin main
# Resolve conflicts if any
git add .
git commit -m "Merge remote changes"
git push origin main
3. 手动解决冲突
The git pull command resulted in a merge conflict in the README.md file. This happens when Git cannot automatically merge changes from the remote repository with your local changes. You’ll need to manually resolve the conflict before proceeding.
Steps to Resolve the Conflict:
- Open the Conflicted File:
Open theREADME.mdfile in your text editor or IDE. You’ll see conflict markers like this:<<<<<<< HEAD Local changes ======= Remote changes >>>>>>> 7006db8
注意, 等号线上方的代表的本地仓库中的内容, 等号线下面的代表的是远程仓库中的内容,
需要根据自己的需求, 进行更改。
<<<<<<< HEADindicates the start of your local changes.=======separates your local changes from the remote changes.>>>>>>> 7006db8indicates the end of the remote changes.
-
Resolve the Conflict:
Edit the file to keep the changes you want. For example:- Keep both changes:
Local changes Remote changes - Keep only local changes:
Local changes - Keep only remote changes:
Remote changes
Remove the conflict markers (
<<<<<<<,=======, and>>>>>>>) after resolving. - Keep both changes:
-
Stage the Resolved File:
Once you’ve resolved the conflict, stage the file:git add README.md -
Commit the Merge:
Commit the resolved changes:git commit -m "Resolved merge conflict in README.md" -
Push Your Changes:
Push the resolved changes to the remote repository:git push origin main
Example Workflow:
# Open README.md and resolve conflicts
nano README.md# Stage the resolved file
git add README.md# Commit the merge
git commit -m "Resolved merge conflict in README.md"# Push the changes
git push origin main
Additional Notes:
- If you’re unsure how to resolve the conflict, you can use a merge tool like
meld,kdiff3, or the built-in tools in your IDE (e.g., VS Code). - To abort the merge and start over (if needed), run:
git merge --abort
小结
全局配置git 上的用户名和email:
git config --global user.name "username"git config --global user.email 1234567@email.com
在本地的client 的git, 配置git初始化默认的分支由master 变为main;
git config --global init.defaultBranch main
upload
一 : 上传大量文件(适用于在github上 刚新建一个的仓库A)
1.在本地新建工程文件夹T,将所有待上传的文件拷贝到T中;
2.在T中空白处,点击git bash here; 在github 上点击copy 刚刚仓库A的地址;
3.使用 git clone “仓库A的地址” ,从github 上拉取该仓库到本地;
4.在本地T中, cd到仓库A的路径下,注意到此时在显示 (main),代表进入到该仓库中;
5.在T中将待上传的文件拷贝到 仓库A中, 输入 “git add .” ,注意空格和点号;
6.输入 git commit -m “your logs infor” ;
7.输入 git push -u origin main, 将本地仓库push 到 github 上面,完成代码上传。
note: git add . : 是将当前目录下所有文件添加到 待上传区域;
git add xx.txt : 可以指定当前目录下待上传的文件;
git push -u origin main: -u 代表首次提交, 后续更新提交时,可以不用;
remote
二:本地仓库远程连接到 github 上已经有的仓库。
1.在本地文件夹T中空白处,点击git bash here; 输入git init;
2.将本地的仓库关联到Github上:
git remote add origin https://github.com/h-WAVES/test0913
-
选中待上传的文件, 文件之间空格隔开;
git add file1 fiel2; -
备注此次操作的信息
git commit -m “logs” -
上传之前先进行Pull 确认一下;如果在github上初始化仓库时,使用第二个;
git pull origin main
git pull --rebase origin main -
待上传的文件push 到远程仓库中;
git push origin main
## delete
三 删除远程仓库中的文件夹1.在本地文件夹T中空白处,点击git bash here; 输入git init;2.git clone 项目地址, cd 到该对应的路径下 3.git rm -r folder/4. git commit -m "delete folder"5. git push origin main完成删除
OpenSSL SSL_read: Connection was reset, errno 10054; 解除SSL 验证:
git config --global http.sslVerify "false"
当github 创建仓库时,选择了初始化.gitignore 和 README.md 时,
此时在github 上和本地的仓库由于文件的不同出现不匹配的情况:对于error: failed to push some refsto‘远程仓库地址’git pull --rebase origin main
相关文章:
git 项目的更新
更新项目 当自己的本地项目与 远程的github 的仓库已经建立远程连接时, 则直接按照下面的步骤, 将本地的项目代码更新到远程仓库。 # Stage the resolved file git add README.md <file1> <file2># To stage all changes: git add .# Comm…...
【Rust自学】17.3. 实现面向对象的设计模式
喜欢的话别忘了点赞、收藏加关注哦,对接下来的教程有兴趣的可以关注专栏。谢谢喵!(・ω・) 17.3.1. 状态模式 状态模式(state pattern) 是一种面向对象设计模式,指的是一个值拥有的内部状态由数个状态对象(…...
51c视觉~CV~合集10
我自己的原文哦~ https://blog.51cto.com/whaosoft/13241694 一、CV创建自定义图像滤镜 热图滤镜 这组滤镜提供了各种不同的艺术和风格化光学图像捕捉方法。例如,热滤镜会将图像转换为“热图”,而卡通滤镜则提供生动的图像,这些图像看起来…...
如何安全地管理Spring Boot项目中的敏感配置信息
在开发Spring Boot应用时,我们经常需要处理一些敏感的配置信息,比如数据库密码、API密钥等。以下是一个最佳实践方案: 1. 创建配置文件 application.yml(版本控制) spring:datasource:url: ${MYSQL_URL:jdbc:mysql…...
Docker小游戏 | 使用Docker部署2048网页小游戏
Docker小游戏 | 使用Docker部署2048网页小游戏 前言项目介绍项目简介项目预览二、系统要求环境要求环境检查Docker版本检查检查操作系统版本三、部署2048网页小游戏下载镜像创建容器检查容器状态检查服务端口安全设置四、访问2048网页小游戏五、总结前言 在当今快速发展的技术世…...
RabbitMQ深度探索:消息幂等性问题
RabbitMQ 消息自动重试机制: 让我们消费者处理我们业务代码的时候,如果抛出异常的情况下,在这时候 MQ 会自动触发重试机制,默认的情况下 RabbitMQ 时无限次数的重试需要认为指定重试次数限制问题 在什么情况下消费者实现重试策略…...
Linux网络 | 进入数据链路层,学习相关协议与概念
前言:本节内容进入博主讲解的网络层级中的最后一层:数据链路层。 首先博主还是会线代友友们认识一下数据链路层的报文。 然后会带大家重新理解一些概念,比如局域网交换机等等。然后就是ARP协议。 讲完这些, 本节任务就算结束。 那…...
芝法酱学习笔记(2.6)——flink-cdc监听mysql binlog并同步数据至elastic-search和更新redis缓存
一、需求背景 在有的项目中,尤其是进销存类的saas软件,一开始为了快速把产品做出来,并没有考虑缓存问题。而这类软件,有着复杂的业务逻辑。如果想在原先的代码中,添加redis缓存,改动面将非常大,…...
JavaScript系列(58)--性能监控系统详解
JavaScript性能监控系统详解 📊 今天,让我们深入探讨JavaScript的性能监控系统。性能监控对于保证应用的稳定性和用户体验至关重要。 性能监控基础概念 🌟 💡 小知识:JavaScript性能监控是指通过收集和分析各种性能指…...
GESP2023年12月认证C++六级( 第三部分编程题(1)闯关游戏)
参考程序代码: #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <string> #include <map> #include <iostream> #include <cmath> using namespace std;const int N 10…...
git 新项目
新项目git 新建的项目如何进行git 配置git git config --global user.name "cc" git config --global user.email ccexample.com配置远程仓库路径 // 添加 git remote add origin http://gogs/cc/mc.git //如果配错了,删除 git remote remove origin初…...
系统URL整合系列视频一(需求方案)
视频 系统URL整合系列视频一(需求方案) 视频介绍 (全国)某大型分布式系统Web资源URL整合需求实现方案讲解。当今社会各行各业对软件系统的web资源访问权限控制越来越严格,控制粒度也越来越细。安全级别提高的同时也增…...
Vue.js 使用组件库构建 UI
Vue.js 使用组件库构建 UI 在 Vue.js 项目中,构建漂亮又高效的用户界面(UI)是很重要的一环。组件库就是你开发 UI 的好帮手,它可以大大提高开发效率,减少重复工作,还能让你的项目更具一致性和专业感。今天…...
计算图 Compute Graph 和自动求导 Autograd | PyTorch 深度学习实战
前一篇文章,Tensor 基本操作5 device 管理,使用 GPU 设备 | PyTorch 深度学习实战 本系列文章 GitHub Repo: https://github.com/hailiang-wang/pytorch-get-started PyTorch 计算图和 Autograd 微积分之于机器学习Computational Graphs 计算图Autograd…...
51单片机入门_05_LED闪烁(常用的延时方法:软件延时、定时器延时;while循环;unsigned char 可以表示的数字是0~255)
本篇介绍编程实现LED灯闪烁,需要学到一些新的C语言知识。由于单片机执行的速度是非常快的,如果不进行延时的话,人眼是无法识别(停留时间要大于20ms)出LED灯是否在闪烁所以需要学习如何实现软件延时。另外IO口与一个字节位的数据对应关系。 文…...
如何获取sql数据中时间的月份、年份(类型为date)
可用自带的函数month来实现 如: 创建表及插入数据: create table test (id int,begindate datetime) insert into test values (1,2015-01-01) insert into test values (2,2015-02-01) 执行sql语句,获取月份: select MONTH(begindate)…...
【单层神经网络】softmax回归的从零开始实现(图像分类)
softmax回归 该回归分析为后续的多层感知机做铺垫 基本概念 softmax回归用于离散模型预测(分类问题,含标签) softmax运算本质上是对网络的多个输出进行了归一化,使结果有一个统一的判断标准,不必纠结为什么要这么算…...
使用开源项目:pdf2docx,让PDF转换为Word
目录 1.安装python 2.安装 pdf2docx 3.使用 pdf2docx 转换 PDF 到 Word pdf2docx:GitCode - 全球开发者的开源社区,开源代码托管平台 环境:windows电脑 1.安装python Download Python | Python.org 最好下载3.8以上的版本 安装时记得选择上&#…...
保姆级教程Docker部署KRaft模式的Kafka官方镜像
目录 一、安装Docker及可视化工具 二、单节点部署 1、创建挂载目录 2、运行Kafka容器 3、Compose运行Kafka容器 4、查看Kafka运行状态 三、集群部署 四、部署可视化工具 1、创建挂载目录 2、运行Kafka-ui容器 3、Compose运行Kafka-ui容器 4、查看Kafka-ui运行状态 …...
ChatGPT提问技巧:行业热门应用提示词案例--咨询法律知识
ChatGPT除了可以协助办公,写作文案和生成短视频脚本外,和还可以做为一个法律工具,当用户面临一些法律知识盲点时,可以向ChatGPT咨询获得解答。赋予ChatGPT专家的身份,用户能够得到较为满意的解答。 1.咨询法律知识 举…...
利用ngx_stream_return_module构建简易 TCP/UDP 响应网关
一、模块概述 ngx_stream_return_module 提供了一个极简的指令: return <value>;在收到客户端连接后,立即将 <value> 写回并关闭连接。<value> 支持内嵌文本和内置变量(如 $time_iso8601、$remote_addr 等)&a…...
进程地址空间(比特课总结)
一、进程地址空间 1. 环境变量 1 )⽤户级环境变量与系统级环境变量 全局属性:环境变量具有全局属性,会被⼦进程继承。例如当bash启动⼦进程时,环 境变量会⾃动传递给⼦进程。 本地变量限制:本地变量只在当前进程(ba…...
Unity3D中Gfx.WaitForPresent优化方案
前言 在Unity中,Gfx.WaitForPresent占用CPU过高通常表示主线程在等待GPU完成渲染(即CPU被阻塞),这表明存在GPU瓶颈或垂直同步/帧率设置问题。以下是系统的优化方案: 对惹,这里有一个游戏开发交流小组&…...
多场景 OkHttpClient 管理器 - Android 网络通信解决方案
下面是一个完整的 Android 实现,展示如何创建和管理多个 OkHttpClient 实例,分别用于长连接、普通 HTTP 请求和文件下载场景。 <?xml version"1.0" encoding"utf-8"?> <LinearLayout xmlns:android"http://schemas…...
Docker 运行 Kafka 带 SASL 认证教程
Docker 运行 Kafka 带 SASL 认证教程 Docker 运行 Kafka 带 SASL 认证教程一、说明二、环境准备三、编写 Docker Compose 和 jaas文件docker-compose.yml代码说明:server_jaas.conf 四、启动服务五、验证服务六、连接kafka服务七、总结 Docker 运行 Kafka 带 SASL 认…...
连锁超市冷库节能解决方案:如何实现超市降本增效
在连锁超市冷库运营中,高能耗、设备损耗快、人工管理低效等问题长期困扰企业。御控冷库节能解决方案通过智能控制化霜、按需化霜、实时监控、故障诊断、自动预警、远程控制开关六大核心技术,实现年省电费15%-60%,且不改动原有装备、安装快捷、…...
使用Matplotlib创建炫酷的3D散点图:数据可视化的新维度
文章目录 基础实现代码代码解析进阶技巧1. 自定义点的大小和颜色2. 添加图例和样式美化3. 真实数据应用示例实用技巧与注意事项完整示例(带样式)应用场景在数据科学和可视化领域,三维图形能为我们提供更丰富的数据洞察。本文将手把手教你如何使用Python的Matplotlib库创建引…...
Fabric V2.5 通用溯源系统——增加图片上传与下载功能
fabric-trace项目在发布一年后,部署量已突破1000次,为支持更多场景,现新增支持图片信息上链,本文对图片上传、下载功能代码进行梳理,包含智能合约、后端、前端部分。 一、智能合约修改 为了增加图片信息上链溯源,需要对底层数据结构进行修改,在此对智能合约中的农产品数…...
【JVM面试篇】高频八股汇总——类加载和类加载器
目录 1. 讲一下类加载过程? 2. Java创建对象的过程? 3. 对象的生命周期? 4. 类加载器有哪些? 5. 双亲委派模型的作用(好处)? 6. 讲一下类的加载和双亲委派原则? 7. 双亲委派模…...
为什么要创建 Vue 实例
核心原因:Vue 需要一个「控制中心」来驱动整个应用 你可以把 Vue 实例想象成你应用的**「大脑」或「引擎」。它负责协调模板、数据、逻辑和行为,将它们变成一个活的、可交互的应用**。没有这个实例,你的代码只是一堆静态的 HTML、JavaScript 变量和函数,无法「活」起来。 …...
