[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
[Practical Git] Clean up commits with git rebase的更多相关文章
- git操作之git clean删除一些没有git add的文件
删除 一些 没有 git add 的 文件: git clean 参数 -n 显示 将要 删除的 文件 和 目录 -f 删除 文件,-df 删除 文件 和 目录
- git clean用法
git clean用法 想批量删除branch中新加的文件(untracked files),,git reset --hard不行- 首先确认要删除的文件 git clean -fd -n ...
- Git合并特定commits 到另一个分支
https://ariejan.net/2010/06/10/cherry-picking-specific-commits-from-another-branch/ http://blog.csdn ...
- git format-patch & git apply & git clean
一.打补丁 git format-patch & git apply 最近在工作中遇到打补丁的需求,一来觉得直接传文件有些low(而且我尝试了一下,差点把项目代码毁了) ,二来也是想学习一下, ...
- [译]git clean
git clean命令用来从你的工作目录中删除所有没有tracked过的文件. git clean经常和git reset --hard一起结合使用. 记住reset只影响被track过的文件, 所以 ...
- git clean 使用方法
删除 一些 没有 git add 的 文件: git clean 参数 -n 显示 将要 删除的 文件 和 目录 -f 删除 文件,-df 删除 文件 和 目录 git clean -n git c ...
- git clean 删除忽略文件 和 未被跟踪文件及文件夹
git clean 删除忽略文件 和 未被跟踪文件及文件夹 概念 首先我们需要认清 忽略的文件 和 未被跟踪的文件 忽略的文件:.gitignore 中忽略的文件 未被跟踪的文件:没有被忽略,但是还没 ...
- Git分支合并:Merge、Rebase的选择
git代码合并:Merge.Rebase的选择 - iTech - 博客园http://www.cnblogs.com/itech/p/5188932.html Git如何将一个分支的修改同步到另一个 ...
- git clean使用总结
git clean移除工作区中untracked的文件(即:需要先add).一直都是用rm来操作……
随机推荐
- 让Windows Server 2008 + IIS 7+ ASP.NET 支持10万个同时请求
具体设置如下: 1. 调整IIS 7应用程序池队列长度 由原来的默认1000改为65535. IIS Manager > ApplicationPools > Advanced Setti ...
- c# 控件闪烁处理方法
如果你在Form中绘图的话,不论是不是采用的双缓存,都会看到图片在更新的时候都会不断地闪烁,解决方法就是在这个窗体的构造函数中增加以下三行代码:请在构造函数里面底下加上如下几行:SetStyle(Co ...
- apache开源项目--Shiro
安全是企业应用中不可缺少的功能,在众多权限框架中,Shiro(其前身是JSecurity)因其简单而又不失强大的特点引起了不少开发者的注 意.随着Grails的关注度越来越高,在Grails社区也出现 ...
- GIS:揭开你神秘的面纱
转自:http://www.cnblogs.com/gisangela/archive/2013/02/20/2918884.html#!comments GIS从出现到为人所知,只不过经历了短短的几 ...
- HDU 1163 Eddy's digital Roots
Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- 【Python】linux安装tornado
想写个页面,又不想用tomcat,同事说可以用tornado,试一下 1 我从网上找了个hello world类似的程序,复制粘贴运行,提示 ImportError: No module named ...
- unity3d切换场景时,背景音乐保持播放
首先创建两个场景: One,Two 再创建一个空游戏对象: GameObject,并添加AudioSource组件,把要播放的音乐拖放进去 给GameObject添加脚本AlwayAudio,代码如下 ...
- Unix 基础IO
内核通过文件描述符引用打开的文件,通常通过open函数或者create函数返回文件描述符. 基本函数: unix中基础的文件操作函数只有5个,分别是open,close,lseek,read,writ ...
- sql-逻辑循环while if
--计算1-100的和 declare @int int=1; declare @total int=0; while(@int<=100) begin set @total=@total+@i ...
- android学习之activity
Activity 的生命周期 和 J2ME 的 MIDlet 一样,在 android 中,Activity 的生命周期交给系统统一管理.与 MIDlet 不同的是安装在 android 中的所有的 ...