gitgithubbranchfeature-branch

How can I compare two Git branches and only list the new commits in the feature/topic (second) branch


I have performed the steps below, but when I compare the develop branch with the feature branch I see two commit messages instead of only just 1 commit that I expect to see. One is the previous commit which is already in develop and the other us the latest commit I made in the feature branch.

  1. I have pulled and merged the local develop branch from a remote branch
  2. Then have created a new branch off of develop
  3. Made changes and added those files and git commit -m "latest changes" in the feature branch
  4. Performed git push to push the feature branch to the remote branch
  5. When I compared develop to feature, I see two commits instead of just one (the one I created in the feature branch)

Why is this happening and how can I resolve this issue?


Solution

  • Answer on your question: you may see difference between two branches by executing git log <parent_branch_name>..<your_feature_branch_name>, for instance git log develop..feature.

    About your situation: As I see situation, the most likely reason for such behaviour is merging develop branch within your local repo. If while merging process (fyi pull operation is combination fetch and merge), merge did not process as fast-forward, then you got another state of develop branch, here could be merge commit, you are able to compare commits hashes.

    In order to prevent such situations, you should use git pull --rebase command for pulling some local branch.

    If you wanted to get latest changes before pushing your local feature branch to the remote server, you could also run git pull --rebase origin develop on your feature branch, then commit's tree will look like you just created your feature branch from develop and put all created commits on feature branch after parent's branch commits.

    I hope, it will be helpful for you!