Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find commits pushed without a pull request?

In my project, it is required to add changes to the master branch using pull requests from feature branches. Currently, the repository is configured to forbid direct pushing to master, but in the past it was allowed.

Is it possible to find commits that were pushed directly to master, without a pull request?

like image 912
pkalinow Avatar asked May 09 '19 11:05

pkalinow


People also ask

Can you push without pull request?

You can do a forced push. The forced push will erase all commit history of the remote repository's branch, and replace it to your branch. Check the answers for doing forced pushes in "How do I properly force a Git push?".

How do you get all commits in a pull request?

You can list the pull requests associated with a commit using GET /repos/:owner/:repo/commits/:commit_sha/pulls , which will show the pull requests which the given commit is associated with. This does mean that you'll need to check every commit to see if its associated with the PR.

Can you make commits without pushing?

So commiting changes without pushing allow the save-load behaviour done locally during development. Once you are happy with your work, you then commit AND push.

Should I squash commits before pull request?

As a general rule, when merging a pull request from a feature branch with a messy commit history, you should squash your commits. There are exceptions, but in most cases, squashing results in a cleaner Git history that's easier for the team to read.


1 Answers

If your pull requests are kept around you can simply check that the second parent of every merge to master is a pull request.

Github keeps pull requests as refs so you can list them with git ls-remote u://r/l refs/pull/*/head, trying to find an equivalent on Atlassian's service felt like swimming in lard so you get to figure that out yourself.

For repos that use the Github convention for publishing pull requests, something like

awk  'ARGIND==1    { prhead[$1]=1; next}
      !prhead[$3]  { print $0, "was not merged from a pull request" }' \
        <(git ls-remote u://r/l refs/pull/*/head)
        <(git rev-list --first-parent --merges master --parents)

will do it.

You can (unsurprisingly enough) push anything the repo's set up to accept, so before your restrictions were in place someone could have pushed a fast-forward. Those will show up as non-merge commits on master:

git rev-list --first-parent --no-merges master

will list every commit that was made on master and not merged.

like image 177
jthill Avatar answered Oct 20 '22 16:10

jthill