Git commits made directly to branch

Sometimes in Git I’ll need to synchronise a long-lived feature branch with master to reduce the likelihood of merge conflicts at a later date. One of the problems with doing this is that git log is filled with all the commits from the branch I’ve merged in, making it difficult to see the commits made on the feature branch.

Fortunately, there are two extra flags which can be passed to git log which sort out this problem:

  • --no-merges: As the name implies, hides any merge commits.
  • --first-parent: Only shows commits originally made to this branch, i.e. not any brought in by merges (which by definition were made to another branch).

Putting this all together, if you want to see the commit messages and diffs for commits made originally to the branch you are currently on, the following command will do the trick:

git log -p --no-merges --first-parent

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.