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

相关推荐
春生野草2 小时前
Gituee
git·gitee
222you2 小时前
Git推送本地仓库到远程
git
小贾要学习3 小时前
如何在Linux操作系统环境下使用git命令提交文件到远程仓库
linux·运维·git
J2虾虾3 小时前
WebStorm的项目绑定Git并上传到gitee
git·gitee·webstorm
虾说羊4 小时前
git分支管理介绍和stash命令
git
71-36 小时前
git 和 tortoisegit的快速使用教学(上传至gitee或GitHub)
git·gitee
唐青枫10 小时前
为什么 .gitignore 不生效?其实你忘了用 git rm --cached!
git
代码or搬砖1 天前
Git学习笔记(三)
笔记·git·学习
虾说羊1 天前
git连接远程仓库并拉去推送以及克隆命令
git
IT~狂男1 天前
GIT 实战命令操作大全,代码变动,推动,修改备注,撤销(篇幅一)
git