Bitbucket - Single commit for all the commit's

686 views Asked by At

I am currently using BitBucket as version control for my project. I see different node (In the image with black dots/multiple commits) of Branch graph on multiple commits. How can I make sure only one node is present on branch graph for all commit I make? In other words all commits must be seen as 1 commit and not incremental

Image 1

I have tried using git commit --amend -m "Message" but it always gives me

error: failed to push some refs hint:'git pull' before pushing again

So I git pull and push again which creates a new commit.

1

There are 1 answers

7
matt On BEST ANSWER

What you're asking to do is perfectly reasonable; I like to do it too. I can just keep making commits on my branch, and then when I am ready to push, I squash them all down to one commit, and push. So the people seeing my PR see it as a single finished product; they don't need to see the whole history of how I got there.

One way to squash all commits in chain into a single commit is to do a soft reset back to the first commit and then amend that commit. See my three types of regret; this is regret type 1.

However, on the whole I like to use interactive rebase for this. Here is an example. We are working on a branch mybranch and we have made three commits:

* cd591cc (HEAD -> mybranch) z
* cdbe774 y
* 3ce8eaa x
| * e86283a (master) b
|/  
* 4227e7d a

Now I want to push so we can merge to master. But I do not want three commits x and y and z. I want just one commit.

So I say:

git rebase -i 4227e7d

(because that is where the branch started). The editor opens and I see this:

pick 3ce8eaa x
pick cdbe774 y
pick cd591cc z

I rewrite it like this:

pick 3ce8eaa x
squash cdbe774 y
squash cd591cc z

I save and close the editor. The editor opens again so I can write my commit message. I delete everything in the editor and replace it with:

my very cool work

I save and close the editor. Now things look like this:

* bb8c9fb (HEAD -> mybranch) my very cool work
| * e86283a (master) b
|/  
* 4227e7d a

Just what I wanted! My branch is just one commit, and now I am ready to merge (or push for a pull request).