[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
相关文章
- [GIT] Git 工作流程(Git flow, Github flow flow, Git lab flow)
- [Git] 给git命令起别名
- Git fetch和git pull的区别
- [Git] Use and Compare the Different git Reset Options: --hard, --soft, and --mixed
- [NPM] Run npm scripts with git hooks
- [Git] Use git add --patch for better commit history and mitigating bugs
- [Practical Git] Show who changed a line last with git blame
- [Practical Git] Configure global settings with git config
- [Practical Git] Navigate git command pager output with Unix less commands
- 写得好 git 提交信息
- Git:合并分支----git merge命令应用的三种情景
- git工作常用命令
- Git 报错fatal: not a git repository (or any parent up to mount point /) Stopping at filesystem bounda
- GIT ---- 常用 Git 命令清单
- 【Git】利用 GIT 做版本控制
- Jenkins Maven Git 自动化部署