Reputation: 1832
I created a branch t1
from master
branch and made many commits in branch t1
.
Then I made several commits in other branches, merged other branches in t1
etc.
Now I want to find only those commits which I had made in branch t1
(not those commits which came from master branch or any other branch as result of merging)
Upvotes: 1
Views: 77
Reputation: 30858
Unless you are using a pull-request flow, there is not any reliable mechanism to record which commits are done for a specific branch.
The name of a local branch is allowed to be arbitrary. You can create a local branch foo
, and push its new commits to the branch bar
. If the push succeeds, we can only be sure the commits are made for bar
. But it does not guarantee that the commits are made in a local bar
. If you are allowed to directly push foo
to bar
without a pull-request, the system even doesn't have a permanent record that these commits are pushed to bar
. You may find some clues in the commit message of a merge commit, but commit messages can be forged too, not to mention that you may not have strict format rules for commit messages. When the push is fast-forward, the merge commit itself does not even exist. The reflogs may have some clues too, but they are not reliable either as they are bound with local branches and not permanent.
With a systematic pull-request flow, the hosting services, like Github, Gerrit and Gitlab, have solid databases to record which commits are merged to a specific branch. They provide apis or interfaces, which allow users to retrieve these records from the databases.
In your case, you can try:
git log t1 ^master --first-parent --no-merges
But the result is not reliable in theory.
Upvotes: 1
Reputation: 1323263
As explained in "Git: How to list commits on this branch but not from merged branches", you can start with (using log --no-merges
):
git log --no-merges t1 master
That would avoid any merge commit.
Upvotes: 0