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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/69198.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

OpenCV:特征检测总结

目录 一、什么是特征检测&#xff1f; 二、OpenCV 中的常见特征检测方法 1. Harris 角点检测 2. Shi-Tomasi 角点检测 3. Canny 边缘检测 4. SIFT&#xff08;尺度不变特征变换&#xff09; 5. ORB 三、特征检测的应用场景 1. 图像匹配 2. 运动检测 3. 自动驾驶 4.…

windows版的docker如何使用宿主机的GPU

windows版的docker使用宿主机的GPU的命令 命令如下 docker run -it --nethost --gpus all --name 容器名 -e NVIDIA_DRIVER_CAPABILITIEScompute,utility -e NVIDIA_VISIBLE_DEVICESall 镜像名效果 (transformer) rootdocker-desktop:/# python Python 3.9.0 (default, Nov 15 …

Zabbix SQL注入漏洞CVE-2024-42327修复建议

近期&#xff0c;Zabbix官方修复了Zabbix SQL注入漏洞(CVE-2024-42327)。利用该漏洞&#xff0c;具有API访问权限的用户可越权访问高权限用户敏感信息以及执行恶意SQL语句。目前该漏洞技术细节与PoC已在互联网上公开。 一、漏洞情况分析 Zabbix 是一款开源的网络监控和报警系统…

neo4j-在Linux中安装neo4j

目录 切换jdk 安装neo4j 配置neo4j以便其他电脑可以访问 切换jdk 因为我安装的jdk是1.8版本的&#xff0c;而我安装的neo4j版本为5.15,Neo4j Community 5.15.0 不支持 Java 1.8&#xff0c;它要求 Java 17 或更高版本。 所以我需要升级Java到17 安装 OpenJDK 17 sudo yu…

最大矩阵的和

最大矩阵的和 真题目录: 点击去查看 E 卷 100分题型 题目描述 给定一个二维整数矩阵&#xff0c;要在这个矩阵中选出一个子矩阵&#xff0c;使得这个子矩阵内所有的数字和尽量大&#xff0c;我们把这个子矩阵称为和最大子矩阵&#xff0c;子矩阵的选取原则是原矩阵中一块相互…

Windows图形界面(GUI)-QT-C/C++ - QT Dock Widget

公开视频 -> 链接点击跳转公开课程博客首页 -> ​​​链接点击跳转博客主页 目录 一、概述 二、使用场景 1. 工具栏 2. 侧边栏 3. 调试窗口 三、常见样式 1. 停靠位置 2. 浮动窗口 3. 可关闭 4. 可移动 四、属性设置 1. 设置内容 2. 获取内容 3. 设置标题 …

8.PPT:小李-第二次世界大战【21】

目录 NO123 ​ NO4567 ​ NO8\9\10\11​ 图片→格式→大小对话框→锁定纵横比✔动画→飞入→效果选项&#xff1a;方向/序列→开始→持续时间→延迟时间持续时间&#xff1a;1s延迟&#xff1a;0.5s音频剪切时间&#xff1a;0.5s&#xff1a;00:00.500自动换片时间设置&…

React中使用箭头函数定义事件处理程序

React中使用箭头函数定义事件处理程序 为什么使用箭头函数&#xff1f;1. 传递动态参数2. 避免闭包问题3. 确保每个方块的事件处理程序是独立的4. 代码可读性和维护性 示例代码总结 在React开发中&#xff0c;处理事件是一个常见的任务。特别是当我们需要传递动态参数时&#x…

GAN(生成对抗网络,Generative Adversarial Network)

https://www.bilibili.com/video/BV1mp4y187dm/?spm_id_from333.788.recommend_more_video.2&vd_source35b06c13f470dff84c947fa3045bafc3

Docker 国内最新可用镜像源20250205

2年没用dockerhub了结果今天发现镜像无法拉取了&#xff0c;找了很多镜像都无效&#xff0c;连阿里云镜像都不行了&#xff0c;最后找到下面可以用的。 Docker镜像仓库备注hub.urlsa.us.kg可用http://hub.haod.eu.org可用http://hub.chxza.eu.org可用http://ccoc.eu.org部分地…

网站快速收录:如何优化网站音频内容?

本文转自&#xff1a;百万收录网 原文链接&#xff1a;https://www.baiwanshoulu.com/60.html 为了优化网站音频内容以实现快速收录&#xff0c;以下是一些关键的策略和步骤&#xff1a; 一、高质量音频内容创作 原创性&#xff1a; 确保音频内容是原创的&#xff0c;避免使…

【C++】多态详细讲解

本篇来聊聊C面向对象的第三大特性-多态。 1.多态的概念 多态通俗来说就是多种形态。多态分为编译时多态(静态多态)和运⾏时多态(动态多态)。 编译时多态&#xff1a;主要就是我们前⾯讲的函数重载和函数模板&#xff0c;他们传不同类型的参数就可以调⽤不同的函数&#xff0c;通…

【kafka的零拷贝原理】

kafka的零拷贝原理 一、零拷贝技术概述二、Kafka中的零拷贝原理三、零拷贝技术的优势四、零拷贝技术的实现细节五、注意事项一、零拷贝技术概述 零拷贝(Zero-Copy)是一种减少数据拷贝次数,提高数据传输效率的技术。 在传统的数据传输过程中,数据需要在用户态和内核态之间…

本地大模型编程实战(08)自制聊天机器人(2)

文章目录 准备使用简单的提示词使用复杂一点的提示词总结代码 本文将演示使用大语言模型自制聊天机器人。主要的内容有&#xff1a; 使用 LangGraph 进一步完善聊天机器人使用提示词改变 LLM 的能力 我们将同时使用 llama3.1 和 deepseek 做演示。由于 langchain 可能对不同大…

NeuralCF 模型:神经网络协同过滤模型

实验和完整代码 完整代码实现和jupyter运行&#xff1a;https://github.com/Myolive-Lin/RecSys--deep-learning-recommendation-system/tree/main 引言 NeuralCF 模型由新加坡国立大学研究人员于 2017 年提出&#xff0c;其核心思想在于将传统协同过滤方法与深度学习技术相结…

【自动化办公】批量图片PDF自定义指定多个区域识别重命名,批量识别铁路货物运单区域内容改名,基于WPF和飞桨ocr深度学习模型的解决方案

项目背景介绍 铁路货运企业需要对物流单进行长期存档&#xff0c;以便后续查询和审计。不同的物流单可能包含不同的关键信息&#xff0c;通过自定义指定多个区域进行识别重命名&#xff0c;可以使存档的图片文件名具有统一的规范和明确的含义。比如&#xff0c;将包含货物运单…

Qt跨屏窗口的一个Bug及解决方案

如果我们希望一个窗口覆盖用户的整个桌面&#xff0c;此时就要考虑用户有多个屏幕的场景&#xff08;此窗口要横跨多个屏幕&#xff09;&#xff0c;由于每个屏幕的分辨率和缩放比例可能是不同的&#xff0c;Qt底层在为此窗口设置缩放比例&#xff08;DevicePixelRatio&#xf…

LeetCode:63. 不同路径 II

跟着carl学算法&#xff0c;本系列博客仅做个人记录&#xff0c;建议大家都去看carl本人的博客&#xff0c;写的真的很好的&#xff01; 代码随想录 LeetCode&#xff1a;63. 不同路径 II 给定一个 m x n 的整数数组 grid。一个机器人初始位于 左上角&#xff08;即 grid[0][0]…

自定义数据集 使用paddlepaddle框架实现逻辑回归

导入必要的库 import numpy as np import paddle import paddle.nn as nn 数据准备&#xff1a; seed1 paddle.seed(seed)# 1.散点输入 定义输入数据 data [[-0.5, 7.7], [1.8, 98.5], [0.9, 57.8], [0.4, 39.2], [-1.4, -15.7], [-1.4, -37.3], [-1.8, -49.1], [1.5, 75.6…

如何利用maven更优雅的打包

最近在客户现场部署项目&#xff0c;有两套环境&#xff0c;无法连接互联网&#xff0c;两套环境之间也是完全隔离&#xff0c;于是问题就来了&#xff0c;每次都要远程到公司电脑改完代码&#xff0c;打包&#xff0c;通过网盘&#xff08;如果没有会员&#xff0c;上传下载慢…