1

I am using Visual studio 2022 for Git.

I have a 'master' branch and, from master branch, I created another 'feature' branch.
Then I added 2 commits in feature branch

  • Question 1: When I merge the 2 commits to 'master' branch, then in history I can see only one merge commit in 'master' branch.
    When merging, why 2 commits are not showing, but only a merge commit?

  • Question 2: I added a commit in feature branch and then merged to 'master' branch.
    Then later, I reverted this commit in 'master' branch for temporarily taking a build.
    Now when I try to merge the feature branch to master branch for this commit to add to master branch because of merging before, now no commits are showing to merge.
    What would be the best practice to merge the commits again ?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Jiju John
  • 821
  • 3
  • 14
  • 35

1 Answers1

2

when merging why 2 commits are not showing, but only a merge commit?

Because that is what a merge produces: a merge commit, which group the commits from the merged branch to one single commit.

what would be the best practice to merge the commits again ?

You could, on master, revert the revert: that way, you can keep merging the feature branch without having to worry about the past commit (which was reverted on master).


for each commits, I use to add comments so that I can track, but when merging branch, I cannot track this, so is there any way I can avoid this?

2 options:

  • either you can display the log of the merged branch from a merged commit:

    git log <sha>^2
    

(replace <sha> with the reference to a merge commit whose merge history you want to track)

  • or rebase your merged branch on top of target, especially if you are the only one working on feature branch.

    git switch master
    git rebase feature
    

There the history will be linear.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • for each commits, I use to add comments so that I can track, but when merging branch, I cannot track this, so is there any way I can avoid this? – Jiju John Mar 02 '22 at 13:24
  • 1
    @JijuJohn I have edited the answer to address your comment. – VonC Mar 02 '22 at 14:03