[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来操作……
随机推荐
- poj1062
经典的图论建模题: 先拿开的等级问题不看: 每个物品本身的价格就是有一个自定义源点到这个点距离: 有了A物品B物品优惠为W就代表由B到A的有向路权值为W: 最后的最小花费就是源点的点1的最短路径(酋长 ...
- bzoj1854
神奇了 朴素的做法不难想,二分图最大匹配(汗,我其实还是想了一会,太弱了) 左边点集为能打的属性值,右边把武器作为一个点 武器和两个属性连边, 然后和superhero那题差不多,顺次找匹配,找不到了 ...
- bzoj2208:[Jsoi2010]连通数
http://blog.csdn.net/u013598409/article/details/47037499 里面似乎有生成数据的... //我本来的想法是tarjan缩点之后然后将图遍历一遍就可 ...
- [LOJ 1030] Discovering Gold
B - Discovering Gold Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- Can not perform pod install under el capitan (15A279b)
这个问题在stackoverflow上面有过讨论: Can not perform pod install under el capitan (15A279b) 被采纳的答案为:sudo gem in ...
- MAT文件操作
o李YZo 原文 MAT文件打开方法汇总及其他操作 MAT文件简介 为MATLAB使用的一种特有的二进制数据文件.MAT文件可以包含一个或者多个MATLAB 变量.MATLAB通常采用MAT文件把工作 ...
- SSL 通信原理及Tomcat SSL 配置
SSL 通信原理及Tomcat SSL 双向配置 目录1 参考资料 .................................................................. ...
- e2e 自动化集成测试 架构 实例 WebStorm Node.js Mocha WebDriverIO Selenium Step by step (二) 图片验证码的识别
上一篇文章讲了“e2e 自动化集成测试 架构 京东 商品搜索 实例 WebStorm Node.js Mocha WebDriverIO Selenium Step by step 一 京东 商品搜索 ...
- C++ 输入输出流 总结
1.ostream & operator<<(int); 重载了<<符号,用于对int类型的输出.为什么要返回ostream的引用呢? 例如: cout<< ...
- 【暑假】[实用数据结构]UVa11235 Frequent values
UVa 11235 Frequent values Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11241 Accep ...