当前位置: 首页 > news >正文

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:
  1. Generate a PAT:

    • Go to your GitHub account settings: GitHub Tokens.
    • Click Generate new token.
    • Select the appropriate scopes (e.g., repo for full control of private repositories).
    • Generate the token and copy it (you won’t be able to see it again).
  2. 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:
  1. 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).

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

  1. ssh-keygen:

    • This is the command-line tool used to generate, manage, and convert SSH keys.
  2. -t ed25519:

    • The -t flag specifies the type of key to generate.
    • ed25519 is 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 ed25519 with other algorithms, such as:
      • rsa: Older but widely supported algorithm (e.g., -t rsa -b 4096 generates a 4096-bit RSA key).
      • ecdsa: Elliptic Curve Digital Signature Algorithm (e.g., -t ecdsa -b 521 generates a 521-bit ECDSA key).
      • dsa: Older and less secure (not recommended).
  3. -C "your_email@example.com":

    • The -C flag 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.

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:

  1. Compatibility:

    • Some older systems or services may not support modern algorithms like ed25519. In such cases, you might need to use rsa or ecdsa.
  2. Security Requirements:

    • If you have specific security requirements, you might choose an algorithm based on its strength or performance characteristics.
  3. 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:

  1. Generate multiple SSH key pairs (e.g., one for work and one for personal use).
  2. Add the keys to your SSH agent.
  3. Configure your SSH client to use the appropriate key for each repository using the ~/.ssh/config file.

Summary

  • The command ssh-keygen -t ed25519 -C "your_email@example.com" generates a secure SSH key pair using the ed25519 algorithm.
  • You can use different algorithms (-t options) 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/config file.

Let me know if you need further clarification!

  1. 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.
  2. 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:
  1. Install the GitHub CLI: GitHub CLI Installation.
  2. Authenticate with GitHub:
    gh auth login
    
  3. 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:
  1. Enable the credential helper:
    git config --global credential.helper store
    
  2. 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:

  1. 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).
  2. 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>
      
  3. Commit the Merge:
    If there were conflicts, commit the merge:

    git commit -m "Merge remote changes into local branch"
    
  4. 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:

  1. Open the Conflicted File:
    Open the README.md file in your text editor or IDE. You’ll see conflict markers like this:
    <<<<<<< HEAD
    Local changes
    =======
    Remote changes
    >>>>>>> 7006db8
    

注意, 等号线上方的代表的本地仓库中的内容, 等号线下面的代表的是远程仓库中的内容,
需要根据自己的需求, 进行更改。

  • <<<<<<< HEAD indicates the start of your local changes.
  • ======= separates your local changes from the remote changes.
  • >>>>>>> 7006db8 indicates the end of the remote changes.
  1. 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.

  2. Stage the Resolved File:
    Once you’ve resolved the conflict, stage the file:

    git add README.md
    
  3. Commit the Merge:
    Commit the resolved changes:

    git commit -m "Resolved merge conflict in README.md"
    
  4. 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

  1. 选中待上传的文件, 文件之间空格隔开;
    git add file1 fiel2;

  2. 备注此次操作的信息
    git commit -m “logs”

  3. 上传之前先进行Pull 确认一下;如果在github上初始化仓库时,使用第二个;
    git pull origin main
    git pull --rebase origin main

  4. 待上传的文件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 的仓库已经建立远程连接时&#xff0c; 则直接按照下面的步骤&#xff0c; 将本地的项目代码更新到远程仓库。 # Stage the resolved file git add README.md <file1> <file2># To stage all changes: git add .# Comm…...

【Rust自学】17.3. 实现面向对象的设计模式

喜欢的话别忘了点赞、收藏加关注哦&#xff0c;对接下来的教程有兴趣的可以关注专栏。谢谢喵&#xff01;(&#xff65;ω&#xff65;) 17.3.1. 状态模式 状态模式(state pattern) 是一种面向对象设计模式&#xff0c;指的是一个值拥有的内部状态由数个状态对象&#xff08…...

51c视觉~CV~合集10

我自己的原文哦~ https://blog.51cto.com/whaosoft/13241694 一、CV创建自定义图像滤镜 热图滤镜 这组滤镜提供了各种不同的艺术和风格化光学图像捕捉方法。例如&#xff0c;热滤镜会将图像转换为“热图”&#xff0c;而卡通滤镜则提供生动的图像&#xff0c;这些图像看起来…...

如何安全地管理Spring Boot项目中的敏感配置信息

在开发Spring Boot应用时&#xff0c;我们经常需要处理一些敏感的配置信息&#xff0c;比如数据库密码、API密钥等。以下是一个最佳实践方案&#xff1a; 1. 创建配置文件 application.yml&#xff08;版本控制&#xff09; spring:datasource:url: ${MYSQL_URL:jdbc:mysql…...

Docker小游戏 | 使用Docker部署2048网页小游戏

Docker小游戏 | 使用Docker部署2048网页小游戏 前言项目介绍项目简介项目预览二、系统要求环境要求环境检查Docker版本检查检查操作系统版本三、部署2048网页小游戏下载镜像创建容器检查容器状态检查服务端口安全设置四、访问2048网页小游戏五、总结前言 在当今快速发展的技术世…...

RabbitMQ深度探索:消息幂等性问题

RabbitMQ 消息自动重试机制&#xff1a; 让我们消费者处理我们业务代码的时候&#xff0c;如果抛出异常的情况下&#xff0c;在这时候 MQ 会自动触发重试机制&#xff0c;默认的情况下 RabbitMQ 时无限次数的重试需要认为指定重试次数限制问题 在什么情况下消费者实现重试策略…...

Linux网络 | 进入数据链路层,学习相关协议与概念

前言&#xff1a;本节内容进入博主讲解的网络层级中的最后一层&#xff1a;数据链路层。 首先博主还是会线代友友们认识一下数据链路层的报文。 然后会带大家重新理解一些概念&#xff0c;比如局域网交换机等等。然后就是ARP协议。 讲完这些&#xff0c; 本节任务就算结束。 那…...

芝法酱学习笔记(2.6)——flink-cdc监听mysql binlog并同步数据至elastic-search和更新redis缓存

一、需求背景 在有的项目中&#xff0c;尤其是进销存类的saas软件&#xff0c;一开始为了快速把产品做出来&#xff0c;并没有考虑缓存问题。而这类软件&#xff0c;有着复杂的业务逻辑。如果想在原先的代码中&#xff0c;添加redis缓存&#xff0c;改动面将非常大&#xff0c…...

JavaScript系列(58)--性能监控系统详解

JavaScript性能监控系统详解 &#x1f4ca; 今天&#xff0c;让我们深入探讨JavaScript的性能监控系统。性能监控对于保证应用的稳定性和用户体验至关重要。 性能监控基础概念 &#x1f31f; &#x1f4a1; 小知识&#xff1a;JavaScript性能监控是指通过收集和分析各种性能指…...

GESP2023年12月认证C++六级( 第三部分编程题(1)闯关游戏)

参考程序代码&#xff1a; #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 //如果配错了&#xff0c;删除 git remote remove origin初…...

系统URL整合系列视频一(需求方案)

视频 系统URL整合系列视频一&#xff08;需求方案&#xff09; 视频介绍 &#xff08;全国&#xff09;某大型分布式系统Web资源URL整合需求实现方案讲解。当今社会各行各业对软件系统的web资源访问权限控制越来越严格&#xff0c;控制粒度也越来越细。安全级别提高的同时也增…...

Vue.js 使用组件库构建 UI

Vue.js 使用组件库构建 UI 在 Vue.js 项目中&#xff0c;构建漂亮又高效的用户界面&#xff08;UI&#xff09;是很重要的一环。组件库就是你开发 UI 的好帮手&#xff0c;它可以大大提高开发效率&#xff0c;减少重复工作&#xff0c;还能让你的项目更具一致性和专业感。今天…...

计算图 Compute Graph 和自动求导 Autograd | PyTorch 深度学习实战

前一篇文章&#xff0c;Tensor 基本操作5 device 管理&#xff0c;使用 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灯闪烁&#xff0c;需要学到一些新的C语言知识。由于单片机执行的速度是非常快的&#xff0c;如果不进行延时的话&#xff0c;人眼是无法识别(停留时间要大于20ms)出LED灯是否在闪烁所以需要学习如何实现软件延时。另外IO口与一个字节位的数据对应关系。 文…...

如何获取sql数据中时间的月份、年份(类型为date)

可用自带的函数month来实现 如&#xff1a; 创建表及插入数据&#xff1a; create table test (id int,begindate datetime) insert into test values (1,2015-01-01) insert into test values (2,2015-02-01) 执行sql语句,获取月份&#xff1a; select MONTH(begindate)…...

【单层神经网络】softmax回归的从零开始实现(图像分类)

softmax回归 该回归分析为后续的多层感知机做铺垫 基本概念 softmax回归用于离散模型预测&#xff08;分类问题&#xff0c;含标签&#xff09; softmax运算本质上是对网络的多个输出进行了归一化&#xff0c;使结果有一个统一的判断标准&#xff0c;不必纠结为什么要这么算…...

使用开源项目:pdf2docx,让PDF转换为Word

目录 1.安装python 2.安装 pdf2docx 3.使用 pdf2docx 转换 PDF 到 Word pdf2docx&#xff1a;GitCode - 全球开发者的开源社区,开源代码托管平台 环境&#xff1a;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除了可以协助办公&#xff0c;写作文案和生成短视频脚本外&#xff0c;和还可以做为一个法律工具&#xff0c;当用户面临一些法律知识盲点时&#xff0c;可以向ChatGPT咨询获得解答。赋予ChatGPT专家的身份&#xff0c;用户能够得到较为满意的解答。 1.咨询法律知识 举…...

大数据学习栈记——Neo4j的安装与使用

本文介绍图数据库Neofj的安装与使用&#xff0c;操作系统&#xff1a;Ubuntu24.04&#xff0c;Neofj版本&#xff1a;2025.04.0。 Apt安装 Neofj可以进行官网安装&#xff1a;Neo4j Deployment Center - Graph Database & Analytics 我这里安装是添加软件源的方法 最新版…...

CVPR 2025 MIMO: 支持视觉指代和像素grounding 的医学视觉语言模型

CVPR 2025 | MIMO&#xff1a;支持视觉指代和像素对齐的医学视觉语言模型 论文信息 标题&#xff1a;MIMO: A medical vision language model with visual referring multimodal input and pixel grounding multimodal output作者&#xff1a;Yanyuan Chen, Dexuan Xu, Yu Hu…...

Mac软件卸载指南,简单易懂!

刚和Adobe分手&#xff0c;它却总在Library里给你写"回忆录"&#xff1f;卸载的Final Cut Pro像电子幽灵般阴魂不散&#xff1f;总是会有残留文件&#xff0c;别慌&#xff01;这份Mac软件卸载指南&#xff0c;将用最硬核的方式教你"数字分手术"&#xff0…...

从零实现STL哈希容器:unordered_map/unordered_set封装详解

本篇文章是对C学习的STL哈希容器自主实现部分的学习分享 希望也能为你带来些帮助~ 那咱们废话不多说&#xff0c;直接开始吧&#xff01; 一、源码结构分析 1. SGISTL30实现剖析 // hash_set核心结构 template <class Value, class HashFcn, ...> class hash_set {ty…...

【HTTP三个基础问题】

面试官您好&#xff01;HTTP是超文本传输协议&#xff0c;是互联网上客户端和服务器之间传输超文本数据&#xff08;比如文字、图片、音频、视频等&#xff09;的核心协议&#xff0c;当前互联网应用最广泛的版本是HTTP1.1&#xff0c;它基于经典的C/S模型&#xff0c;也就是客…...

以光量子为例,详解量子获取方式

光量子技术获取量子比特可在室温下进行。该方式有望通过与名为硅光子学&#xff08;silicon photonics&#xff09;的光波导&#xff08;optical waveguide&#xff09;芯片制造技术和光纤等光通信技术相结合来实现量子计算机。量子力学中&#xff0c;光既是波又是粒子。光子本…...

【Java学习笔记】BigInteger 和 BigDecimal 类

BigInteger 和 BigDecimal 类 二者共有的常见方法 方法功能add加subtract减multiply乘divide除 注意点&#xff1a;传参类型必须是类对象 一、BigInteger 1. 作用&#xff1a;适合保存比较大的整型数 2. 使用说明 创建BigInteger对象 传入字符串 3. 代码示例 import j…...

Golang——6、指针和结构体

指针和结构体 1、指针1.1、指针地址和指针类型1.2、指针取值1.3、new和make 2、结构体2.1、type关键字的使用2.2、结构体的定义和初始化2.3、结构体方法和接收者2.4、给任意类型添加方法2.5、结构体的匿名字段2.6、嵌套结构体2.7、嵌套匿名结构体2.8、结构体的继承 3、结构体与…...

解析奥地利 XARION激光超声检测系统:无膜光学麦克风 + 无耦合剂的技术协同优势及多元应用

在工业制造领域&#xff0c;无损检测&#xff08;NDT)的精度与效率直接影响产品质量与生产安全。奥地利 XARION开发的激光超声精密检测系统&#xff0c;以非接触式光学麦克风技术为核心&#xff0c;打破传统检测瓶颈&#xff0c;为半导体、航空航天、汽车制造等行业提供了高灵敏…...

uniapp 小程序 学习(一)

利用Hbuilder 创建项目 运行到内置浏览器看效果 下载微信小程序 安装到Hbuilder 下载地址 &#xff1a;开发者工具默认安装 设置服务端口号 在Hbuilder中设置微信小程序 配置 找到运行设置&#xff0c;将微信开发者工具放入到Hbuilder中&#xff0c; 打开后出现 如下 bug 解…...