git基本操作

解决冲突

场景:分支feature/slot分支上的代码想要合并到develop分支上,但是有冲突出现

  1. 本地develop分支拉取远程最新develop分支的代码

    //在develop分支上
    git pull origin develop

  2. 将本地develop分支的代码合并到本地feature/slot分支

    //在feature/slot分支上
    git merge develop

  3. 解决冲突

    //上述合并之后,就可以参考code中存在冲突的位置,然后在相应的文件中解决冲突

  4. 提交代码

    git add .
    git commit -m 'chore: merge branch develop into feature/slot'

本地创建一个新的分支并关联远程分支

复制代码
git checkout -b feature/slot origin/feature/slot

拉取代码

复制代码
1. 最先创建时使用git clone命令
2. git pull origin xxx  拉取远程分支最新代码

git修改远程仓库地址

  • 查看远程仓库

    复制代码
    git remote -v
  • 修改关联的远程仓库

    复制代码
    git remote set-url origin 新的远程仓库地址

git提交代码流程

一个分支上不小心提交了两个commit

​1. 先删除远程的分支

复制代码
git push origin --delete feature/form-layout(原分支名)
  1. 在本地新建一个临时分支

    git checkout -b temp

  2. 将原来分支上的一个commit 应用到temp分支

    1. 查看原分支上的所有commit
      git log feature/form-layout(原分支名)
    2. 在temp分支上使用命令将commit应用到temp分支上
      git cherry-pick abcdef123456(id号)

4.删除本地的原分支

复制代码
git branch -d feature/form-layout
  1. 本地分支重命名

    //在temp分支上进行操作,将temp重命名为feature/form-layout
    git branch -m feature/form-layout

  2. 提交远程

相关推荐
极小狐37 分钟前
极狐GitLab Git LFS 速率限制如何设置?
运维·git·ssh·gitlab·github
极小狐44 分钟前
如何解决极狐GitLab 合并冲突?
人工智能·git·机器学习·gitlab
一袋米扛几楼981 小时前
【GIT】github中的仓库如何删除?
git·github
hjm47021921 小时前
GIT 使用小记
git
程序猿chen11 小时前
JVM考古现场(二十五):逆熵者·时间晶体的永恒之战(进阶篇)
java·jvm·git·后端·程序人生·java-ee·改行学it
biubiubiu070614 小时前
git提交
git
ljh57464911914 小时前
git撤销最近一次commit
git
三体世界15 小时前
Linux 管道理解
linux·c语言·开发语言·c++·git·vscode·visual studio
道长没有道观15 小时前
ubuntu系统下部署使用git教程
git·ubuntu·elasticsearch
codingandsleeping18 小时前
Git 子模块 (Submodule) 使用介绍
前端·git