There does not seem to be a way to retrieve all of the actually existing commits in a repository
<!---
Please read this!
Before opening a new issue, make sure to search for keywords in the issues
filtered by the "regression" or "type::bug" label:
- https://gitlab.com/gitlab-org/gitlab/issues?label_name%5B%5D=regression
- https://gitlab.com/gitlab-org/gitlab/issues?label_name%5B%5D=type::bug
and verify the issue you're about to submit isn't a duplicate.
--->
### Summary
There does not seem to be a way to return only real commits in a repository using the commits endpoint. On the one hand, if you simply request the commits you get only the commits on the default branch. On the other hand, if you pass ´?all=true` then you get commits from all branches, including commits that have been deleted.
<!-- Summarize the bug encountered concisely. -->
### Steps to reproduce
Create a merge request on a repository, force push a change, and then request all of the commits back via
```
curl https://$gitlab_url/api/v4/projects/$project_id/repository/commits?all=true
```
You will find the deleted commits listed there. If you drop the `?all=true` then you do not get the commits on the side branch.
<!-- Describe how one can reproduce the issue - this is very important. Please use an ordered list. -->
### Example Project
<!-- If possible, please create an example project here on GitLab.com that exhibits the problematic
behavior, and link to it here in the bug report. If you are using an older version of GitLab, this
will also determine whether the bug is fixed in a more recent version. -->
Example project: https://gitlab.com/simon.cfr/deleted_commits
### What is the current *bug* behavior?
<!-- Describe what actually happens. -->
Consider then
```
$ curl "https://gitlab.com/api/v4/projects/48531827/repository/commits?all=true" | jq '.[].short_id'
"f5e7dc0e"
"600d756a"
"5a645fb2"
"0d796363"
"f229eaa2"
```
vs
```
$ curl "https://gitlab.com/api/v4/projects/48531827/repository/commits?ref_name=foo" | jq '.[].short_id'
"0d796363"
"f5e7dc0e"
```
Note that several of those commits do not actually exist in the repository; it is not possible to check them out.
### What is the expected *correct* behavior?
<!-- Describe what you should see instead. -->
There should be a way to request only the commits that actually exist and are possible to check out; in this case I would expect it to be
* 0d796363
* f5e7dc0e
### Investigation (by @vyaklushin)
These commits are kept in special references: `refs/merge-requests/*` and `refs/keep-around/*`. `git log --all` command also picks them and returns in the response.
To solve that we can update Commit API to add a new filter option.
I tested several versions and these two options worked for me:
```
git log --branches --tags
```
or
```
git log --exclude="refs/merge-requests/*" --exclude="refs/keep-around/*" --all
```
issue