当前位置: 首页 > 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.咨询法律知识 举…...

论文解读:交大港大上海AI Lab开源论文 | 宇树机器人多姿态起立控制强化学习框架(二)

HoST框架核心实现方法详解 - 论文深度解读(第二部分) 《Learning Humanoid Standing-up Control across Diverse Postures》 系列文章: 论文深度解读 + 算法与代码分析(二) 作者机构: 上海AI Lab, 上海交通大学, 香港大学, 浙江大学, 香港中文大学 论文主题: 人形机器人…...

STM32+rt-thread判断是否联网

一、根据NETDEV_FLAG_INTERNET_UP位判断 static bool is_conncected(void) {struct netdev *dev RT_NULL;dev netdev_get_first_by_flags(NETDEV_FLAG_INTERNET_UP);if (dev RT_NULL){printf("wait netdev internet up...");return false;}else{printf("loc…...

在 Nginx Stream 层“改写”MQTT ngx_stream_mqtt_filter_module

1、为什么要修改 CONNECT 报文&#xff1f; 多租户隔离&#xff1a;自动为接入设备追加租户前缀&#xff0c;后端按 ClientID 拆分队列。零代码鉴权&#xff1a;将入站用户名替换为 OAuth Access-Token&#xff0c;后端 Broker 统一校验。灰度发布&#xff1a;根据 IP/地理位写…...

【算法训练营Day07】字符串part1

文章目录 反转字符串反转字符串II替换数字 反转字符串 题目链接&#xff1a;344. 反转字符串 双指针法&#xff0c;两个指针的元素直接调转即可 class Solution {public void reverseString(char[] s) {int head 0;int end s.length - 1;while(head < end) {char temp …...

如何将联系人从 iPhone 转移到 Android

从 iPhone 换到 Android 手机时&#xff0c;你可能需要保留重要的数据&#xff0c;例如通讯录。好在&#xff0c;将通讯录从 iPhone 转移到 Android 手机非常简单&#xff0c;你可以从本文中学习 6 种可靠的方法&#xff0c;确保随时保持连接&#xff0c;不错过任何信息。 第 1…...

相机从app启动流程

一、流程框架图 二、具体流程分析 1、得到cameralist和对应的静态信息 目录如下: 重点代码分析: 启动相机前,先要通过getCameraIdList获取camera的个数以及id,然后可以通过getCameraCharacteristics获取对应id camera的capabilities(静态信息)进行一些openCamera前的…...

高效线程安全的单例模式:Python 中的懒加载与自定义初始化参数

高效线程安全的单例模式:Python 中的懒加载与自定义初始化参数 在软件开发中,单例模式(Singleton Pattern)是一种常见的设计模式,确保一个类仅有一个实例,并提供一个全局访问点。在多线程环境下,实现单例模式时需要注意线程安全问题,以防止多个线程同时创建实例,导致…...

MySQL 知识小结(一)

一、my.cnf配置详解 我们知道安装MySQL有两种方式来安装咱们的MySQL数据库&#xff0c;分别是二进制安装编译数据库或者使用三方yum来进行安装,第三方yum的安装相对于二进制压缩包的安装更快捷&#xff0c;但是文件存放起来数据比较冗余&#xff0c;用二进制能够更好管理咱们M…...

Redis:现代应用开发的高效内存数据存储利器

一、Redis的起源与发展 Redis最初由意大利程序员Salvatore Sanfilippo在2009年开发&#xff0c;其初衷是为了满足他自己的一个项目需求&#xff0c;即需要一个高性能的键值存储系统来解决传统数据库在高并发场景下的性能瓶颈。随着项目的开源&#xff0c;Redis凭借其简单易用、…...

tomcat入门

1 tomcat 是什么 apache开发的web服务器可以为java web程序提供运行环境tomcat是一款高效&#xff0c;稳定&#xff0c;易于使用的web服务器tomcathttp服务器Servlet服务器 2 tomcat 目录介绍 -bin #存放tomcat的脚本 -conf #存放tomcat的配置文件 ---catalina.policy #to…...