[Git] Rebase basic

You've made some commits to a feature branch, but you've also committed a hotfix on master that would make a merge messy. Check out the kennel branch so you can rebase it on master.

git checkout kennel

 

OK, you're on the kennel branch. Our goal is to be able to merge kennel back into master without conflicts or a merge commit. Rebase the current kennel branch on master.

git rebase master

 

With the rebase complete, kennel should merge with master cleanly. Switch branches back to master

git checkout master

 

We're on master, and we know the kennel will merge cleanly. Go ahead and merge in thekennel branch.

git merge kennel

 

Your co-worker has pushed changes to the master branch on the origin repo. Retrieve it without merging it so we can replay our work on top of it.

git fetch

 

Now that your local repo knows of the latest changes on origin/master, move your mastercommits after the commits from origin/master.

git rebase

 

Your co-worker has pushed before you yet again. Better fetch the changes...

git fetch

 

Now run another rebase to move your commit after the latest fetched one.

git rebase

 

Uh, oh! Looks like the rebase is in conflict this time! Edit index.html to fix the conflicting lines. We want to keep our version with Cats and Dogs.

复制代码
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Our Cat-alog</title>
  </head>
  <body>
    <nav>
      <ul>
<<<<<<< HEAD
        <li><a href="cat.html">Cats</a></li>
        <li><a href="dog.html">Dogs</a></li>
=======
        <li><a href="cat.html">Felines</a></li>
        <li><a href="dog.html">Canines</a></li>
>>>>>>> Add dogs.
      </ul>
    </nav>
  </body>
</html>
复制代码
复制代码
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Our Cat-alog</title>
  </head>
  <body>
    <nav>
      <ul>
        <li><a href="cat.html">Cats</a></li>
        <li><a href="dog.html">Dogs</a></li>.
      </ul>
    </nav>
  </body>
</html>
复制代码

 

Now mark the conflicts in "index.html" as resolved.

git add index.html

 

Now that all conflicts have been resolved and those files added, continue the current rebase in process.

git rebase --continue

 

posted @   Zhentiw  阅读(320)  评论(0编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示