2

let's say we create a branch new_branch. We change 1 file there, commit this one file, push and create a pull request to parent rep/master.

meanwhile parent rep changed quite a bit, let's say 100 files were changed but that 1 file wasn't touched.

And still, pull request diff will show that only 1 file was changed.

So how GIT understands that actually 1 file needs to be merged only, and not 101 files. I mean parent rep/master compare to child rep/new_branch in fact 101 files were changed and not 1 file..

VextoR
  • 5,087
  • 22
  • 74
  • 109
  • 2
    You're basically asking "how does a version control system work", the answer to which is quite broad... But all git needs to do is follow the history of `new_branch` to see what has been changed in that branch since it last branched off the main tree. And that is only 1 file. – deceze Jun 03 '14 at 14:47
  • Just a hunch, but I think what you're interested in is merging. You want to merge the changes from master into your main branch. – Jordan Reiter Jun 03 '14 at 15:44

1 Answers1

4

It is a three-way merge, which means git will compare your evolution against the common ancestor between:

  • your branch
  • the parentRepo branch

That difference is the one applied for the merge.

See more at "Why is a 3-way merge advantageous over a 2-way merge?".

A----C  (yourBranch: 1 file modified, compared to A, the common ancestor)
 \
  --B   (parentRepo master: 100 files modified)

When merging:

A----C  
 \    \
  --B--D (only one file is merged to parentRepo branch)

See more at "Pro Git book: Basic Merging":

http://git-scm.com/figures/18333fig0316-tn.png

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250