[Practical Git] Clean up commits with git rebase
Sometimes its nice to clean up commits before merging them into your main code repo; in this lesson, we go over using git rebase
to squash
commits together and then rename the condensed commit message. We also talk about potential issues with rebasing and where to be careful.
//First, you can fetch the remote branch git fetch //Then can see the logs between remote branch and local branch git log origin/master..
git rebase -i origin/master
One thing to note is that a rebase is destructive. It actually changes your Git history. You shouldn't use a rebase on code that's already been put in your master branch on your remote repository that other developers might be using. A rebase has the same function as a Git merge, but it cleans up and destroys history, whereas a merge preserves all history, and includes a merge commit.
The bottom line is that, as long as you only need to clean up commits that you've made locally or in a pull request branch, you can use rebase to clean them up before you merge them into your main master branch.
If you have already pushed your commits to a pull request branch, then after you run the rebase, because it's destructive, you'll need to run:
git push -f
, for force, to let Git know that you're OK with destroying the history that's in a remote branch.
Again, be careful with this, and only use a rebase and a force push if you're working on code that hasn't been made public yet. One other thing to note is that, if at any time during a rebase, you realize you've made a mistake, you can get run the Git rebase command with the abort flag to stop the rebase, and return your repo to its state before you started the rebase.
git rebase --abort
相关文章
- Git、本地仓库、远程仓库、IDEA集成Git
- 一文吃透 VS Code+Git 操作(vs code中git的相关配置与使用)
- git如何退出vim_git提交的命令
- PyCharm下如何使用Git「建议收藏」
- gitee pycharm_怎么把git上放到pycharm
- idea使用git stash
- [原创] git的前世,和BitKeeper
- 一个成功的Git分支模型
- git 报错Git fatal: Unknown index entry format xxxxx的错误解决方法
- Git删除本地分支_idea删除git分支
- git拉取代码如何解决冲突_Git工具-git pull拉取代码时冲突的解决办法[通俗易懂]
- 如何自建一个git服务器,搭建Git服务器,真的很简单
- 使用git命令与vscode从零开始对远程代码仓库进行拉取、提交、合并、推送分支等操作在项目中的实践
- 软件测试|Github基础命令与 IDE 的 Git 集成
- 【Git】Git 基础命令 ( 查看提交记录 git log | 版本回滚 git reset | 撤销回滚 git reflog )
- Linux下的Git版本控制管理实战(linux的git)
- 版本Linux 查看 Git 版本信息的方法(linux查看git)
- git和春天、Linux和Git一起收获成功(springlinux)
- Linux下使用Git的快速安装步骤(linux下git的安装)
- Linux下安装Git的指引(在linux下安装git)
- 分析学习Oracle深入理解使用With 分析(oracle使用with)
- 从Oracle中挖掘洞见坚实的With表(oracle with表)
- GitHub 弃用了基于账户密码的 Git 操作认证