0

I cloned the master and started doing he my work . Due to permissions I push the branch to my fork . I then sent a pull request to my master and someone with permission does the merge . I notice that Github.com creates a merge commit snapshot which to me looks like just a diff of the entire changes which is actually not necessary but helpful in the sense I can just look at merge commit to see the entire diff . I can see the same sha has as my own branch - hence it looks like the merge is an extra commit which probably aint nexeccary since its a fast forward ?

master - a
myfork(computer) - a->b->c
myfork(github) - a->b->c

Pull request myfork - master (which it says I can automatically merge) shows the entire diff and then when I merge it , it shows up as master - a->b->c-d . The d is a merge commit which I think it not really required because it is a fast forward ? Can someone explain why does this happen ? I think this is the same scenario if I rebase master if master had gone ahead , but that has not happened . Master is still at when I merge .

Nishant
  • 20,354
  • 18
  • 69
  • 101

1 Answers1

2

It is true that the merge commit is not required in this case, but it is not an error to create one anyway. git merge on the command line supports the --no-ff option, which will avoid fast-forwarding a merge even if a fast-forward is possible. That switch is probably what GitHub is using.

The extra merge commit is redundant in terms of making the latest commit have the correct code, and it does clutter up the history slightly. But it does have the advantage of adding extra metadata about the merge – it contains the date when the merge was made, and makes it more explicit in history that someone else’s code was merged into the branch. GitHub probably weighed these advantages and disadvantages and decided that the extra commit was a sensible default. This question has more discussion on when fast-forwarding is and isn’t appropriate.

Community
  • 1
  • 1
Rory O'Kane
  • 29,210
  • 11
  • 96
  • 131
  • 1
    Bulls Eye! Thanks . Thats interesting . Looks like this is for enabling the reviewer to see the entire diff in one page so that he can quickly see the entire change and merge .... The full diff of all commits is actually helpful sometimes... Also appreicate the link to why FF/no FF question ... Cheers for that link ! – Nishant Nov 03 '13 at 10:06