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的更多相关文章

  1. git操作之git clean删除一些没有git add的文件

    删除 一些 没有 git add 的 文件: git clean 参数 -n 显示 将要 删除的 文件 和  目录 -f 删除 文件,-df 删除 文件 和 目录

  2. git clean用法

    git clean用法   想批量删除branch中新加的文件(untracked files),,git reset --hard不行-   首先确认要删除的文件 git clean -fd -n ...

  3. Git合并特定commits 到另一个分支

    https://ariejan.net/2010/06/10/cherry-picking-specific-commits-from-another-branch/ http://blog.csdn ...

  4. git format-patch & git apply & git clean

    一.打补丁 git format-patch & git apply 最近在工作中遇到打补丁的需求,一来觉得直接传文件有些low(而且我尝试了一下,差点把项目代码毁了) ,二来也是想学习一下, ...

  5. [译]git clean

    git clean命令用来从你的工作目录中删除所有没有tracked过的文件. git clean经常和git reset --hard一起结合使用. 记住reset只影响被track过的文件, 所以 ...

  6. git clean 使用方法

    删除 一些 没有 git add 的 文件: git clean 参数 -n 显示 将要 删除的 文件 和  目录 -f 删除 文件,-df 删除 文件 和 目录 git clean -n git c ...

  7. git clean 删除忽略文件 和 未被跟踪文件及文件夹

    git clean 删除忽略文件 和 未被跟踪文件及文件夹 概念 首先我们需要认清 忽略的文件 和 未被跟踪的文件 忽略的文件:.gitignore 中忽略的文件 未被跟踪的文件:没有被忽略,但是还没 ...

  8. Git分支合并:Merge、Rebase的选择

    git代码合并:Merge.Rebase的选择 - iTech - 博客园http://www.cnblogs.com/itech/p/5188932.html Git如何将一个分支的修改同步到另一个 ...

  9. git clean使用总结

    git clean移除工作区中untracked的文件(即:需要先add).一直都是用rm来操作……

随机推荐

  1. 在Google被封的那些日子裏,我們這樣科學上網

    回到正題,如果某天你喜歡的網站被封了,你工作的郵箱無法訪問了,該如何用正確姿勢實現科學上網呢?雷鋒網為大家整理了數個小技巧. 1.FreeGate類傻瓜工具 很多人第一次用翻墻,應該是從FreeGat ...

  2. C#String与string大小写的区别

    string是c#中的类 String是.net Framework的类 用string需要通过再次编译,所以直接用String速度会更快··· string是关键字,而String不是··· str ...

  3. String中intern的方法

    首先查看官方API那个的解释: ——————————————————————————————————————— intern public String intern() 返回字符串对象的规范化表示形 ...

  4. WCF配置文件详解(一)

    <?xml version="1.0" encoding="utf-8" ?><configuration>    <!-- &l ...

  5. MySQL性能指标及计算方法

    绝大多数MySQL性能指标可以通过以下两种方式获取: (1)mysqladmin 使用mysqladmin extended-status命令获得的MySQL的性能指标,默认为累计值.如果想了解当前状 ...

  6. c#保存datagridview中的数据时报错 “动态SQL生成失败。找不到关键信息”

    ilovejinglei 原文 C#中保存datagridview中的数据时报错"动态SQL生成失败.找不到关键信息" 问题描述     相关代码 using System; us ...

  7. 用JDK自带的工具生成客户端调用Webservice的代码

    JAVA下客户端调用Webservice代码简直是让人心生畏惧,今日尝试,做记录如下,参考网上的众多解决方案,下面这种方式是比较简单的. 在jdk的bin目录下有一个wsimport.exe的工具,使 ...

  8. ASP.NET_验证控件(class0620)

    为什么使用验证控件 当需要让用户输入数据时,用户有可能输入不符合我们程序逻辑要求的信息,所以我们要对输入进行验证. 客户端验证(用户体验,减少服务器端压力) 服务器端验证(防止恶意攻击,客户端js很容 ...

  9. 如何添加网站for Linux(绑定域名)

    [以下配置的路径以阿里云提供的标准环境路径为准,如果您另行安装,请根据实际安装路径配置].   1.cd /alidata/server/httpd/conf/vhosts/ 进入绑定域名所在目录, ...

  10. Hello,Ubuntu(安装过程中遇到的问题及解决)

    2013-02-23 不折腾不舒服(>_<).在虚拟机上运行Ubuntu程序一多就明显卡顿,感觉效率不高.为了流畅使用Ubuntu,也便于将来学习Vim/Emacs,我决定在笔记本的Win ...