How could I list commits in a pull request or feature branch? #3421

Closed
opened 2025-11-02 05:12:28 -06:00 by GiteaMirror · 6 comments
Owner

Originally created by @yanOnGithub on GitHub (Jun 3, 2019).

I tried a lot of these.
https://www.google.com/search?q=git+show+commits+on+a+feature+branch

Let's use this as an example:
https://github.com/go-gitea/gitea/pull/7089/commits

There are 7 commits in this PR. Suppose I am standing in the head of the feature branch after running one of the following
git checkout "mrsdizzie:fix-7068"
git checkout 177092a

Is there any way to list the 7 commits on CLI? Any git commands? Any shell scripts? Any wget/curl/REST API?

Further question: Suppose I am in the middle (cbfc6aa), can I list the 4 commits starting from 8263e09?

Originally created by @yanOnGithub on GitHub (Jun 3, 2019). I tried a lot of these. https://www.google.com/search?q=git+show+commits+on+a+feature+branch Let's use this as an example: https://github.com/go-gitea/gitea/pull/7089/commits There are 7 commits in this PR. Suppose I am standing in the head of the feature branch after running one of the following git checkout "mrsdizzie:fix-7068" git checkout 177092a Is there any way to list the 7 commits on CLI? Any git commands? Any shell scripts? Any wget/curl/REST API? Further question: Suppose I am in the middle (cbfc6aa), can I list the 4 commits starting from 8263e09?
GiteaMirror added the type/question label 2025-11-02 05:12:28 -06:00
Author
Owner

@zeripath commented on GitHub (Jun 3, 2019):

ok, you can find the merge-base of the branch and the master

git merge-base master HEAD

Then you do:

git log $MERGE_BASE..HEAD

So all together:

git log $(git merge-base master branch-name)..branch-name
@zeripath commented on GitHub (Jun 3, 2019): ok, you can find the merge-base of the branch and the master `git merge-base master HEAD` Then you do: `git log $MERGE_BASE..HEAD` So all together: ``` git log $(git merge-base master branch-name)..branch-name ```
Author
Owner

@yanOnGithub commented on GitHub (Jun 3, 2019):

https://github.com/go-gitea/gitea/issues/7117#issuecomment-498330543
git merge-base master HEAD
git log $(git merge-base master branch-name)..branch-name

I tried "git merge-base" also. Before PR merge, it produced the commit where the feature branch started as desired. After PR merge, it produced the commit where the merge occurred, which is not what I want.

https://github.com/go-gitea/gitea/pull/7089
I cannot even checkout 177092aa4b now. Can we find any test cases in https://github.com/go-gitea/gitea/pulls ? git checkout 160e7ed worked at the current HEAD of the master branch. Am I missing anything?

git checkout 177092aa4b40457654123d13ebcf921843b7a877
fatal: reference is not a tree: 177092aa4b40457654123d13ebcf921843b7a877

git log $(git merge-base master branch-name)..branch-name
This behavior also changes before and after PR merge.

@yanOnGithub commented on GitHub (Jun 3, 2019): https://github.com/go-gitea/gitea/issues/7117#issuecomment-498330543 `git merge-base master HEAD` `git log $(git merge-base master branch-name)..branch-name` I tried "git merge-base" also. Before PR merge, it produced the commit where the feature branch started as desired. After PR merge, it produced the commit where the merge occurred, which is not what I want. https://github.com/go-gitea/gitea/pull/7089 I cannot even checkout 177092aa4b40457654123d13ebcf921843b7a877 now. Can we find any test cases in https://github.com/go-gitea/gitea/pulls ? `git checkout 160e7ed` worked at the current HEAD of the master branch. Am I missing anything? ``` git checkout 177092aa4b40457654123d13ebcf921843b7a877 fatal: reference is not a tree: 177092aa4b40457654123d13ebcf921843b7a877 ``` `git log $(git merge-base master branch-name)..branch-name` This behavior also changes before and after PR merge.
Author
Owner

@zeripath commented on GitHub (Jun 4, 2019):

Yes, it would change after a pr merge because the merge base would be the merge point at that point.

You would need to use the shas of the trees pre-merge to get the original merge-base but look at git's own documentation about merge-base.

@zeripath commented on GitHub (Jun 4, 2019): Yes, it would change after a pr merge because the merge base would be the merge point at that point. You would need to use the shas of the trees pre-merge to get the original merge-base but look at git's own documentation about merge-base.
Author
Owner

@yanOnGithub commented on GitHub (Jun 4, 2019):

Are there any REST API? Can I wget and parse the html of the PR webpage?

@yanOnGithub commented on GitHub (Jun 4, 2019): Are there any REST API? Can I wget and parse the html of the PR webpage?
Author
Owner

@zeripath commented on GitHub (Jun 4, 2019):

What are you trying to get exactly? Using Gitea feature branches as an example for looking at commits on branches is not necessarily the most sensible - we squash our commits into a single commit with the pr # in the commit line and once those features are squashed most developers will simply delete the branch losing that information.

Other projects may use a merge branch strategy which will keep the history at a cost of a potentially complicated tree. In those cases you should be able to interrogate the git history as described above. Or if you prefer graphically with gitk and I think there's a graphical representation available in Gitea.

In terms of APIs - apart from git I don't think there is one and in general I think we should avoid creating APIs to git - git is itself an API. I think however our PullRequest APIs should give you the git URL to pull/fetch the branch - and if they don't or it's not obvious then we should change that.

@zeripath commented on GitHub (Jun 4, 2019): What are you trying to get exactly? Using Gitea feature branches as an example for looking at commits on branches is not necessarily the most sensible - we squash our commits into a single commit with the pr # in the commit line and once those features are squashed most developers will simply delete the branch losing that information. Other projects may use a merge branch strategy which will keep the history at a cost of a potentially complicated tree. In those cases you should be able to interrogate the git history as described above. Or if you prefer graphically with gitk and I think there's a graphical representation available in Gitea. In terms of APIs - apart from git I don't think there is one and in general I think we should avoid creating APIs to git - git is itself an API. I think however our PullRequest APIs should give you the git URL to pull/fetch the branch - and if they don't or it's not obvious then we should change that.
Author
Owner

@yanOnGithub commented on GitHub (Jun 4, 2019):

What are you trying to get exactly?

https://nvie.com/posts/a-successful-git-branching-model/
Our team practice git flow. I am handling pull requests, merging, and code review for about 40 developers. When a pull requests comes, I would like to list the changed files from a feature branch and review the code. I would like to exclude files changed on the feature branch as a result of catching up with (daily merging from) the develop branch.

https://try.gitea.io/api/swagger
I am going to try the APIs here.

Since I am also the admin, I can look at the sqlite file (gitea.db) for pull_request.merge_base. Is the merge_base hash frozen at the time of PR creation? I considering doing a set operation like

(git diff --name-only feature_head..merge_base) minus (git diff --name-only develop_head..merge_base)

How can I figure out the parent of pull_request.merged_commit_id? There should be 2 parents. One on the feature branch and another on the develop branch.

git rev-parse $merged_commit_id^1 gives only one result. Maybe I have to parse the output of git log for the line Merge: <develop_hash> <feature_hash>

@yanOnGithub commented on GitHub (Jun 4, 2019): > What are you trying to get exactly? https://nvie.com/posts/a-successful-git-branching-model/ Our team practice git flow. I am handling pull requests, merging, and code review for about 40 developers. When a pull requests comes, I would like to list the changed files from a feature branch and review the code. I would like to exclude files changed on the feature branch as a result of catching up with (daily merging from) the develop branch. https://try.gitea.io/api/swagger I am going to try the APIs here. Since I am also the admin, I can look at the sqlite file (gitea.db) for pull_request.merge_base. Is the merge_base hash frozen at the time of PR creation? I considering doing a set operation like (git diff --name-only feature_head..merge_base) minus (git diff --name-only develop_head..merge_base) How can I figure out the parent of pull_request.merged_commit_id? There should be 2 parents. One on the feature branch and another on the develop branch. `git rev-parse $merged_commit_id^1` gives only one result. Maybe I have to parse the output of `git log` for the line `Merge: <develop_hash> <feature_hash>`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#3421