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. 提交远程

相关推荐
司徒小夜8 小时前
处理git没做修改,但是文件显示变更的情况
git
m0_749317529 小时前
vscode里如何用git
ide·git·vscode
Hello.Reader10 小时前
Git 安装全攻略Linux、macOS、Windows 与源码编译
linux·git·macos
王景程11 小时前
SELinux是什么以及如何编写SELinux策略
git·github
Chuncheng's blog11 小时前
如何基于Mihomo Party http端口配置git与bash命令行代理
git·http·bash
Tom Boom11 小时前
Git常用命令完全指南:从入门到精通
大数据·git·elasticsearch·docker·自动化测试框架
不爱学英文的码字机器13 小时前
[Git] 文件删除
git
DZSpace14 小时前
git stash命令用法
git
Vowwwwwww14 小时前
GIT历史存在大文件的解决办法
前端·git·后端
@BreCaspian15 小时前
Git 推送失败解决教程——error: failed to push some refs to
大数据·git·elasticsearch