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. 函数buf_page_get

    /**************************************************************//** NOTE! The following macros shoul ...

  2. bzoj1856

    这是一道无比涨姿势的题目 首先总结一下这种输入几个数的题目, 一般不是递推就是数学题 显然,这道题用递推是无法做到O(n)的复杂度的 那我们就考虑这是一道数学题了 我已开始纠结在正向思维了,正向求好像 ...

  3. UVa 294 (因数的个数) Divisors

    题意: 求区间[L, U]的正因数的个数. 分析: 有这样一条公式,将n分解为,则n的正因数的个数为 事先打好素数表,按照上面的公式统计出最大值即可. #include <cstdio> ...

  4. Excel 内容粘贴到DataGridView, DataGridView 粘贴到 Excel

    void dataGridView1_KeyDown(object sender, KeyEventArgs e) { if (e.Control && e.KeyCode == Ke ...

  5. 如何将DataTable转换成List<T>呢?

    昨日在工作中,遇到一个问题:需要将查询出来的DataTable数据源,转换成List<T>的泛型集合(已知T类型).第一反应,我想肯定要用到“泛型”(这不是废话吗?都说了要转换成List& ...

  6. linux 查看外网IP

    curl http://iframe.ip138.com/ic.asp curl ifconfig.me curl http://members.3322.org/dyndns/getip

  7. windows 远程桌面连接 RPi 2B

    /************************************************************************* * windows 远程桌面连接 RPi 2B * ...

  8. (七)学习MVC之CodeFirst迁移更新数据库

    1.首先在程序包管理控制台输入:enable-migrations -force ,然后回车: 问题1: The EntityFramework package is not installed on ...

  9. 也用 Log4Net 之将自定义属性记录到文件中 (三)

    也用 Log4Net  之将自定义属性记录到文件中 (三)  即解决了将自定义属性记录到数据库之后.一个新的想法冒了出来,自定义属性同样也能记录到文件中吗?答案是肯定的,因为Log4Net既然已经考虑 ...

  10. process thread Fiber(linux)

    http://blog.chinaunix.net/uid-21084809-id-2215376.html Processes, kernel threads, user threads, and ...