Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to squash commits on Bitbucket after they have been pushed?

I am currently working on a project with multiple others. The problem is that we created a fork of an existed project and need to squash all our commits from after the forking process to a single commit for a pull-request on Bitbucket.

Is there any way (preferably using SourceTree, otherwise terminal) to squash already pushed commits to a single commit, such that the history within Bitbucket of all the commits are also only that one commit plus the commits which were already there before we forked the project?

Take as example just a simple project with a few files in only a master branch.

like image 740
Joshua Avatar asked Jan 08 '16 09:01

Joshua


1 Answers

Use git rebase!

Bitbucket use the Git software.

alex said it already in his post: Use the git rebase -i ourbranchname command!


Commands

Use these commands in the terminal, command prompt or in your cmd:

  1. git rebase -i yourbranchname
  2. A file in a editor program will be automatcally open.
  3. Change all commits from "pick" to "fixup" but one commit must have "pick"!
  4. Save the file and close.
  5. git push -f origin yourbranchname

Helpful resources

  • http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html
  • https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History
  • http://makandracards.com/makandra/527-squash-several-git-commits-into-a-single-commit
like image 188
Suriyaa Avatar answered Sep 26 '22 03:09

Suriyaa