Showing commits made directly to a branch, ignoring merges in Git

前端 未结 3 1414
囚心锁ツ
囚心锁ツ 2020-12-22 21:49

When using git, is there a way to show commits made to a branch, while ignoring all commits that were brought in by merging?

I\'m trying to review the code changes

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-22 22:27

    You can use git cherry for that, it will find you commits that were not yet merged to the upstream, or commits that are on one branch but not the other. So given two branches named "your-branch" and "master":

    git cherry -v your-branch master
    

    will present you list of commits compared with their patch id:

    + c3e441bf4759d4aa698b4a413f1f03368206e82f Updated Readme
    - 2a9b2f5ab1fdb9ee0a630e62ca7aebbebd77f9a7 Fixed formatting
    + e037c1d90b812af27dce6ed11d2db9454a6a74c2 Corrected spelling mistake
    

    You can notice that commits prefixed by "-" are the ones that appear in both branches, whereas those prefixed with "+" are availble only on your branch.

    As an alternative you can use:

    git log --pretty=format:"%h %s" your-branch..master --no-merges
    

    which will show you list of commits done on "your-branch" that are not yet present on "master"

提交回复
热议问题