[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 master
commits 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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 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工具