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

相关推荐
Yulki3 小时前
【经验分享】Git如何连接Github私有仓库
经验分享·git·github
弘毅 失败的 mian3 小时前
Git 多人协作
经验分享·笔记·git
猫腻余腥4 小时前
Git 命令使用教程
git
lanhuazui104 小时前
git常见操作
git
未名编程6 小时前
本地项目上传 GitHub 私有库:GitHub CLI 与 Git 原生双方案详解
git·github
我是一只代码狗6 小时前
git和master分支进行对比差异
git
弘毅 失败的 mian6 小时前
Git 标签管理
经验分享·笔记·git
TPBoreas6 小时前
前端项目 Git 仓库管理策略选择
git
钦拆大仁7 小时前
Git提交代码报错fatal: detected dubious ownership ...
git
C_心欲无痕7 小时前
git - git push同时推送GitHub和Gitee两个远程仓库
git·gitee·github