AlexMA AlexMA - 1 year ago 90
Git Question

Git made a commit with no changes in it automatically after a pull

I committed a change to a file and ran git push; the commit was rejected because my branch was behind its remote counterpart. I then ran git pull and it said

Merge made by the 'recursive' strategy.
. However, it also pulled up my text editor and had me enter a commit message. Why did git automatically generate a commit when I ran git pull? The resulting commit has two parents, but 0 changed files (no changes at all). Now there is a goofy commit on master that says I merged something, but with no real content.

Answer Source

When you run git pull, git actually runs a command equivalent to git fetch followed by git merge. In this case the merge is non-trivial, though - you have commits on two divergent branches that must be consolidated before the commit is made. For simplicity's sake, git has made a "merge commit" to handle the consolidation while maintaining the correctness of each branch's history.

If maintaining the branches' history is not of importance, this question is likely of interest.