Git is based on a directed acyclic graph, it means you cannot exclude or ignore part of the history without compromising the integrity of your repository.
However, you may rebase
your PR branch locally and either:
- Force push you PR branch (only if you know what you are doing)
- Close your PR and create a new one with the rebased history.
To exclude commits from your pull request branch you would perform an interactive rebase locally:
git checkout -b feature/failure-analyzer
git rebase -i HEAD~10 # Where 10 is the number of commits you want to rebase
git push --set-upstream origin feature/feature-analyzer
Let's review this with your scenario:
Fork repository
You forked the project locally
* a (HEAD, master, origin/master)
...
Implement your new feature
During your development flow you made some mistakes and you have noisy commits. Unfortunately you already pushed your changes on your forked repository.
* e implementation done (HEAD, master, origin/master)
* d again oops
* c oops
* b implement feature foo
* a
Clean your work
It is time to clean your commit with
$ git checkout -b feature/foo
$ git rebase -i HEAD~5
Eventually you get this history:
* f implement feature foo (HEAD, feature/foo)
| * e implementation done (master, origin/master)
| * d again oops
| * c oops
| * b implement feature foo
|/
* a
Do the pull request
Now you can push your work and create a new pull request:
$ git push --set-upstream origin feature/foo