My original question:
If I'm not mistaken GitHub keeps every commit pushed to pull requests even after those pull requests are squashed and rebased onto the master branch. Is there a way to make BitBucket cloud do the same?
My clarified real question:
How can I make BitBucket delete the original feature branch when the PR is Squashed and added to master but have the PR page retain the individual commits without squashing them. This way the commit history of the repository is kept clean and I can still go back and inspect individual commits from the PR at a later date if I need to.
Sorry if I still haven't been clear!
Hi Jonathan and welcome to the community.
When you create a pull request, there is an option
Close name-of-source-branch after the pull request is merged
You can leave that unchecked if you want to keep the source branch when a PR is merged.
When someone merges a PR, there is a checkbox also in the Merge dialog, Close source branch, this needs to remain unchecked as well, otherwise the source branch will get deleted when the PR is merged.
Please feel free to let me know if you have any other questions.
I don't think I made my original question very clear, sorry.
What I actually want is for the original feature branch I was working on to be deleted when the PR is Squashed and added to master but for the PR page to retain the individual commits without squashing them. This way the commit history of the repository is kept clean and I can still go back and inspect individual commits from the PR at a later date if I need to.
Anyway, it appears I was able to do what you said and then manually delete the branch. The diff still shows up in the PR but it is the squashed diff of all commits in the PR. I can then use the Open in Source option from the diff and then the 'Check Out' button which provides me the following command.
git fetch && git checkout f69ecf8c7c8d93f5ff990c4d0f9f1b15689565f6
If I run this command in the same local repo I had used to create the PR, it works and puts the repository in a detached head state with the individual commits. But... if I delete that local repo and clone it fresh, the command does not work!
Thank you for the clarification, this helps!
The reason that this issue occurs is because in Bitbucket Cloud, PR are not saved as refs in the repo.
So, if you delete the source branch of a PR, its commits become dangling commits (not associated with any reference).
If you take a fresh clone, these commits are not there because no reference is associated with them anymore (the only reference was the branch, which is now removed upon branch deletion), Git does not fetch commits not associated with a ref.
This is the reason why a fresh clone of the repo doesn't have them and the checkout fails. The local clone you were working on before had these commits already, which is why you can do the checkout.
We have a feature request to have references for pull requests in repos:
Now, these commits (of the deleted source branch) still exist in the repo, until a garbage collection runs.
I can open a feature request to display them, instead of the squash commit. However until the previous request (BCLOUD-5814) is implemented, there would be a chance that at some point they'd stop showing, when a git gc runs and these dangling commits are removed. So, I believe that such a feature request may be dependant on the implementation of BCLOUD-5814.
Please feel free to let me know if you'd like me to open the feature request for you, and also if you have any questions.
Of course! I went ahead and opened the feature request in our issue tracker:
Please feel free to add any feedback and your vote (by selecting the Vote for this issue link) in there.
If you'd like to get notified via email on updates you can select the Start watching this issue link.
Implementation of new features is done as per our policy here and any updates are posted in that public ticket.
Feel free to let me know if you need anything further!
Hey Community! We’re willing to wager that quite a few of you not only use Bitbucket, but administer it too. Our team is excited to share that we’ll be releasing improvements throughout this month of...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events