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).
  2. 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.
  3. Change the Remote URL to SSH:

    • Update your remote repository URL to use SSH instead of HTTPS:
      git remote set-url origin git@github.com:xxxx_name/respitory.git
      
    • 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
    

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

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

相关文章

Java 数据库连接池:HikariCP 与 Druid 的对比

Java 数据库连接池&#xff1a;HikariCP 与 Druid 的对比 数据库连接池&#xff1a;HikariCP 1. 卓越的性能表现 HikariCP 在数据库连接池领域以其卓越的性能脱颖而出。 其字节码经过精心优化&#xff0c;减少了不必要的开销&#xff0c;使得连接获取和释放的速度极快。 在…

【Numpy核心编程攻略:Python数据处理、分析详解与科学计算】1.25 视觉风暴:NumPy驱动数据可视化

1.25 视觉风暴&#xff1a;NumPy驱动数据可视化 目录 #mermaid-svg-i3nKPm64ZuQ9UcNI {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-i3nKPm64ZuQ9UcNI .error-icon{fill:#552222;}#mermaid-svg-i3nKPm64ZuQ9UcNI …

【实践案例】基于大语言模型的海龟汤游戏

文章目录 项目背景提示词构建海龟汤主持人真相判断专家 具体实现流程文心一言大语言模型“海龟汤”插件参考 项目背景 “海龟汤”作为一种聚会类桌游&#xff0c;又称情境推理游戏&#xff0c;是一种猜测情境还原事件真相的智力游戏。其玩法是由出题者提出一个难以理解的事件&…

Spring PropertyPlaceholderConfigurer多配置问题

本文重点是通过例子代码的debug了解PropertyPlaceholderConfigurer的原理 更多可阅读&#xff1a;placeholderconfigurer文档 了解 目录 测试程序如下PropertyPlaceholderConfigurerplaceholderConfigurer1 & placeholderConfigurer2的执行userbean的BeanDefinition应用Pr…

PVE纵览-解锁 PVE 的潜力:配置显卡直通

PVE纵览-解锁 PVE 的潜力&#xff1a;配置显卡直通 文章目录 PVE纵览-解锁 PVE 的潜力&#xff1a;配置显卡直通摘要显卡直通的优势准备工作硬件要求软件要求 启用 IOMMU修改 BIOS 设置配置 PVE 系统 配置显卡直通识别设备编辑配置文件安装必要驱动 常见问题及解决方案显卡直通…

线性调整器——耗能型调整器

线性调整器又称线性电压调节器&#xff0c;以下是关于它的介绍&#xff1a; 基本工作原理 线性调整器的基本电路如图1.1(a)所示,晶体管Q1(工作于线性状态,或非开关状态)构成一个连接直流源V和输出端V。的可调电气电阻,直流源V由60Hz隔离变压器&#xff08;电气隔离和整流&#…

Unity 2D实战小游戏开发跳跳鸟 - 计分逻辑开发

上文对障碍物的碰撞逻辑进行了开发,接下来就是进行跳跳鸟成功穿越过障碍物进行计分的逻辑开发,同时将对应的分数以UI的形式显示告诉玩家。 计分逻辑 在跳跳鸟通过障碍物的一瞬间就进行一次计分,计分后会同步更新分数的UI显示来告知玩家当前获得的分数。 首先我们创建一个用…

机器学习中的关键概念:通过SKlearn的MNIST实验深入理解

欢迎来到我的主页&#xff1a;【Echo-Nie】 本篇文章收录于专栏【机器学习】 1 sklearn相关介绍 Scikit-learn 是一个广泛使用的开源机器学习库&#xff0c;提供了简单而高效的数据挖掘和数据分析工具。它建立在 NumPy、SciPy 和 matplotlib 等科学计算库之上&#xff0c;支持…

vim-plug的自动安装与基本使用介绍

vim-plug介绍 Vim-plug 是一个轻量级的 Vim 插件管理器&#xff0c;它允许你轻松地管理 Vim 插件的安装、更新和卸载。相较于其他插件管理器&#xff0c;vim-plug 的优点是简单易用&#xff0c;速度较快&#xff0c;而且支持懒加载插件&#xff08;即按需加载&#xff09; 自动…

pytorch图神经网络处理图结构数据

人工智能例子汇总&#xff1a;AI常见的算法和例子-CSDN博客 图神经网络&#xff08;Graph Neural Networks&#xff0c;GNNs&#xff09;是一类能够处理图结构数据的深度学习模型。图结构数据由节点&#xff08;vertices&#xff09;和边&#xff08;edges&#xff09;组成&a…

[mmdetection]fast-rcnn模型训练自己的数据集的详细教程

本篇博客是由本人亲自调试成功后的学习笔记。使用了mmdetection项目包进行fast-rcnn模型的训练&#xff0c;数据集是自制图像数据。废话不多说&#xff0c;下面进入训练步骤教程。 注&#xff1a;本人使用linux服务器进行展示&#xff0c;Windows环境大差不差。另外&#xff0…

对比uart iic spi 三种总线的使用

1.uart串口通信 1.1uart的通信总线方式 1.2查询开发板和数据手册对需要进行修改的串口进行设置 例如STM32MP157aaa 1.设置8bit数据位 2.设置无校验位 3.设置1bit停止位 4.设置波特率为115200 5.设置16倍过采样 7.使能发送器 TE 8.使能接收器 RE 9.使能串口 UE10.发送数据&…

【玩转 Postman 接口测试与开发2_016】第13章:在 Postman 中实现契约测试(Contract Testing)与 API 接口验证(上)

《API Testing and Development with Postman》最新第二版封面 文章目录 第十三章 契约测试与 API 接口验证1 契约测试的概念2 契约测试的工作原理3 契约测试的分类4 DeepSeek 给出的契约测试相关背景5 契约测试在 Postman 中的创建方法6 API 实例的基本用法7 API 实例的类型实…

java-(Oracle)-Oracle,plsqldev,Sql语法,Oracle函数

卸载好注册表,然后安装11g 每次在执行orderby的时候相当于是做了全排序,思考全排序的效率 会比较耗费系统的资源,因此选择在业务不太繁忙的时候进行 --给表添加注释 comment on table emp is 雇员表 --给列添加注释; comment on column emp.empno is 雇员工号;select empno,en…

尚硅谷课程【笔记】——大数据之Shell【一】

课程视频&#xff1a;【【尚硅谷】Shell脚本从入门到实战】 一、Shell概述 为什么要学习Shell&#xff1f; 1&#xff09;需要看懂运维人员的Shell程序 2&#xff09;偶尔编写一些简单的Shell程序来管理集群、提高开发效率 什么是Shell&#xff1f; 1&#xff09;Shell是一…

pytorch实现长短期记忆网络 (LSTM)

人工智能例子汇总&#xff1a;AI常见的算法和例子-CSDN博客 LSTM 通过 记忆单元&#xff08;cell&#xff09; 和 三个门控机制&#xff08;遗忘门、输入门、输出门&#xff09;来控制信息流&#xff1a; 记忆单元&#xff08;Cell State&#xff09; 负责存储长期信息&…

CDDIS从2025年2月开始数据迁移

CDDIS 将从 2025 年 2 月开始将我们的网站从 cddis.nasa.gov 迁移到 earthdata.nasa.gov&#xff0c;并于 2025 年 6 月结束。 期间可能对GAMIT联网数据下载造成影响。

【Redis】主从模式,哨兵,集群

主从复制 单点问题&#xff1a; 在分布式系统中&#xff0c;如果某个服务器程序&#xff0c;只有一个节点&#xff08;也就是一个物理服务器&#xff09;来部署这个服务器程序的话&#xff0c;那么可能会出现以下问题&#xff1a; 1.可用性问题&#xff1a;如果这个机器挂了…

华为云kubernetes部署deepseek r1、ollama和open-webui(已踩过坑)

1 概述 ollama是一个管理大模型的一个中间层&#xff0c;通过它你可以下载并管理deepseek R1、llama3等大模型。 open-webui是一个web界面&#xff08;界面设计受到chatgpt启发&#xff09;&#xff0c;可以集成ollama API、 OpenAI的 API。 用常见的web应用架构来类比&#x…

在Mac mini M4上部署DeepSeek R1本地大模型

在Mac mini M4上部署DeepSeek R1本地大模型 安装ollama 本地部署&#xff0c;我们可以通过Ollama来进行安装 Ollama 官方版&#xff1a;【点击前往】 Web UI 控制端【点击安装】 如何在MacOS上更换Ollama的模型位置 默认安装时&#xff0c;OLLAMA_MODELS 位置在"~/.o…