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

相关推荐
今日无bug1 天前
Git 提交:用全栈技术打造智能 Commit Message 生成器
git·全栈
明月_清风1 天前
拒绝盲目 Git:VS Code 神级插件 GitLens 的 9 个进效杀手锏
前端·git
goodspeed4 天前
Git Worktree:多分支并行开发的利器
git·github
雮尘5 天前
让 AI Agent 高效并行开发的命令-git worktree
人工智能·git·agent
南果梨6 天前
OpenClaw 完整教程!从安装到使用(官方脚本版)
前端·git·开源
Selicens7 天前
git批量删除本地多余分支
前端·git·后端
闲云一鹤8 天前
Git LFS 扫盲教程 - 你不会还在用 Git 管理大文件吧?
前端·git·前端工程化
vibecoding日记11 天前
为什么我就想要「线性历史 + Signed Commits」,GitHub 却把我当猴耍 🤬🎙️
git·编程工具
程序员小崔日记11 天前
如何将代码轻松上传到 Gitee?Git 使用全攻略!
git·gitee·上传