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
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.
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:Now I want to push so we can merge to
master
. But I do not want three commitsx
andy
andz
. I want just one commit.So I say:
(because that is where the branch started). The editor opens and I see this:
I rewrite it like this:
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:
I save and close the editor. Now things look like this:
Just what I wanted! My branch is just one commit, and now I am ready to merge (or push for a pull request).