Commits missing from file's history dropdown on Bitbucket Cloud UI
Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.
Summary
Users sometimes might notice that, while reviewing a specific file's history on Bitbucket Cloud Source view, some commits will be missing from the dropdown.
Cause
There are a few causes that could explain why any specific commits are not appearing on the dropdown:
- Pull Request merged with Squash commits: In case the specific commit that is missing was pushed to a branch that was later merged through a Pull Request using Squash Merge Strategy, due to the way that this merge strategy works, all commits within that branch are "squashed" into a new single commit, which is then added to the destination branch, making all previous commits unreachable. In this case, it is not possible to check a specific version for this file in one of those commits, only through the "squashed commit";
- History rewrite: It is also possible for this commit to be removed from your Git history through any history rewriting techniques, such as a Git reset. In these cases, this commit no longer belongs to your Git history, making it so that the commit is no longer present in the dropdown;
- Git's history simplification: Git performs by default a simplification within your commits history, which could cause some commits to be omitted from your repository. This happens most often whenever a file is reverted back to its original state, causing any commits in the middle to be omitted. Git's history simplification can be really confusing at best, so let's check an example to make it more clear:
Within a new local repository, create a file with some initial content:
$ cd history_simplification
$ git init
Initialized empty Git repository
$ echo "Initial content" >> file.txt
$ git add file.txt
$ git commit -m "Initial commit"
[master (root-commit) 0f21dfa] Initial commit
1 file changed, 1 insertion(+)
create mode 100644 file.txt
Now, create a new feature branch and add some more lines:
$ git checkout -b feature
Switched to a new branch 'feature'
$ echo "Feature line" >> file.txt
$ git commit -am "Added line from Feature branch"
[feature aed6115] Added line from Feature branch
1 file changed, 1 insertion(+)
While you worked on that, you had to create a new hotfix branch and make some changes to that file as well:
$ git checkout master -b hotfix
Switched to a new branch 'hotfix'
$ echo "Hotfix line" >> file.txt
$ git commit -am "Hotfix line"
[hotfix eb88254] Hotfix line
1 file changed, 1 insertion(+)
Feeling satisfied with our changes, merge the feature branch first:
$ git checkout master
Switched to branch 'master'
$ git merge feature
Updating 0f21dfa..aed6115
Fast-forward
file.txt | 1 +
1 file changed, 1 insertion(+)
Take a look at the file.txt git log:
$ git log file.txt
commit aed6115828203808be3976d3b464ebabd431da56 (feature)
Date: Tue Oct 4 17:56:46 2022 -0300
Added line from Feature branch
commit 0f21dfa703d57ef795e0d39f986caba6c0d1d2ac
Date: Tue Oct 4 17:56:13 2022 -0300
Initial commit
All looks good! Now, try to merge that Hotfix branch:
$ git merge hotfix
Auto-merging file.txt
CONFLICT (content): Merge conflict in file.txt
Automatic merge failed; fix conflicts and then commit the result.
A merge conflict appeared. This is expected since both branches made changes on the same line for that file. In order to fix this, edit the file and leave only the lines introduced by the hotfix branch:
$ echo "Initial content" > file.txt
$ echo "Hotfix line" >> file.txt
$ git commit -am "Fixed merge conflicts"
[master 15ca106] Fixed merge conflicts
Lastly, check how that file.txt git log is looking:
$ git log file.txt
commit eb88254956a618367f58fc18e7bdc64565ee6929 (hotfix)
Date: Tue Oct 4 17:58:30 2022 -0300
Hotfix line
commit 0f21dfa703d57ef795e0d39f986caba6c0d1d2ac
Date: Tue Oct 4 17:56:13 2022 -0300
Initial commit
Solution
We can see that all the work from the feature branch is no longer listed. That happens because Git is suppressing those commits since they are irrelevant to the file's history. We can confirm that by adding the --full-history flag to our command:
$ git log --full-history file.txt
commit 15ca106d812a4efa975096f243befd102494d2d5 (HEAD -> master)
Merge: aed6115 eb88254
Date: Tue Oct 4 18:01:04 2022 -0300
Fixed merge conflicts
commit eb88254956a618367f58fc18e7bdc64565ee6929 (hotfix)
Date: Tue Oct 4 17:58:30 2022 -0300
Hotfix line
commit aed6115828203808be3976d3b464ebabd431da56 (feature)
Date: Tue Oct 4 17:56:46 2022 -0300
Added line from Feature branch
commit 0f21dfa703d57ef795e0d39f986caba6c0d1d2ac
Date: Tue Oct 4 17:56:13 2022 -0300
Initial commit
With this, we can confirm that the commits still exist, however, due to the way Git keeps track of files' history in a more simplified way, they are suppressed by default while looking at the logs.
Bitbucket Cloud also has an open Feature Request with the Engineering Team in order to make the full history appear by default on the UI, as found in Bitbucket Server/DC: BCLOUD-21200 - File history in Bitbucket doesn't show full history