1

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?

Petros
  • 8,862
  • 3
  • 39
  • 38
Kar
  • 790
  • 13
  • 36
  • The merge is a commit if it was not a fast-forward (including representative commit messages in the question would be useful). I recommend _not_ having a local develop branch. Create new feature branches off of origin/develop instead. Then the new branches are naturally starting at the correct remote commit. It also avoids needing to remember to merge/pull-forward a generally needless branch. It’s okay to checkout origin/develop in a detached head mode (eg. to build+test) as well if committing work to feature branches. – user2864740 May 31 '20 at 05:55
  • Can you please let me know the command to create a feature branch off origin/develop branch – Kar May 31 '20 at 12:54
  • 1
    Thanks @Petros for editing , Learnt how to make it better – Kar May 31 '20 at 13:30
  • The process is largely the same as for branching from develop, only there is no need to pull/merge the develop branch. The commands I use go about like: git fetch —tags —all —force ; git checkout origin/develop ; git checkout -b feature/foo – user2864740 May 31 '20 at 17:01

1 Answers1

2

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!

AGrigorii
  • 142
  • 6
  • FWIW: I’m a fan of not having a local develop (or other mainline) branches, as I find the process to keep these up-to-date is unnecessary in a feature branch model. Being able to work via remote names (or direct commits, etc.) is one strength of the git model over some alternative SCM models. – user2864740 May 31 '20 at 20:08
  • @AGrigorii , I will surely try `git pull --rebase` ....What i used to do always is I first `git checkout develop` branch and then run `git fetch origin/develop` and then `git merge origin/develop` and finally I create a feature branch from the local branch – Kar May 31 '20 at 20:49