-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
74 lines (55 loc) · 2.29 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
Let's represent mathematically relationship between two files:
def issame(file1, file2):
if (each and every line of file1 and file2 is exactly the same):
return True
return False
def difference(file1, file2):
return {'added': (all the lines that are added)
'deleted': (all the lines that are deleted)
}
A<------B<-------C
difference(C, A) = difference(B, A) + difference(C, B)
If git goes down to this level, it can do all merge for you automatically. But it doesn't
make sense if whichever change that comes last is previliged to become the ultimate change.
so, what git does is just tracking the difference, and let you decide which ones to keep when
there is conflict. Then, what is considered conflicts in git? Changes made to the same file, but
are different changes:
def singlefileconflict(file1, file2):
if issame(file1, file2):
return False
if isnewfile(file1):
return False
commonances = findcommonances(file1, file2)
if difference(file1, commonances) == difference(file2, commonances):
return False
return True
def isconflict():
for file1, file2 in all_files():
if singlefileconflict(file1, file2):
return True
return False
def merge():
if not isconflict():
do it
def commit():
new_blob = creat_snapshot()
new_blob.mama = HEAD
HEAD = new_blob
def branch():
new_branch = get_a_branch_pointer()
new_branch = HEAD
return new_branch
def checkout(branch):
HEAD = branch
The case of merging local branch to corresponding remote branch is no different from merging
two local branches together. 'pull' is essentially 'fetch' + 'merge'
merge --rebase (put local ones on top) preferrable
merge (folow timeline)
Possible cases:
1. fast forward: easiest, just a simple shift
2. no conflict: stack one on top of another based on timeline
3. conflict: solve your conflict, make it conflict free
Two merge ways:
1. non-rebase: maybe based on timeline
2. rebase: put local on top. If it's local merge to remote, local commits on top
if it's one branch merge to another, one branch would be on top.