1 |
Hello! |
2 |
|
3 |
|
4 |
As the prefix branch is not the last case where people may run into |
5 |
problems with merging due to the conversion from SVN to Git I feel like |
6 |
writing about it here. |
7 |
|
8 |
|
9 |
In this mail |
10 |
============ |
11 |
- The problem |
12 |
- Merges in SVN |
13 |
- Merges in Git |
14 |
- Consequences |
15 |
|
16 |
- Dealing with it |
17 |
- The concept |
18 |
- Realization |
19 |
|
20 |
|
21 |
The problem |
22 |
=========== |
23 |
|
24 |
Merges in SVN |
25 |
------------- |
26 |
In SVN people select what commits are merged from where to where |
27 |
manually: SVN, merge commits 3 to 10 to branch "prefix" please. What |
28 |
has been merge is tracked in the mind of the person merging and in log |
29 |
messages. |
30 |
|
31 |
|
32 |
Merges in Git |
33 |
------------- |
34 |
In Git there's another place where merges are saved: in the DAG of commits: |
35 |
|
36 |
- A commit with several children/successors is a branch point |
37 |
- A commit with several parents is a merge point |
38 |
|
39 |
When merging one branch into another Git runs the DAG up (into the past) |
40 |
from both commits until it finds a shared merge or branch point: that's |
41 |
the point up to where both branches were synced last time. History |
42 |
after that point is then merged over, nothing before. |
43 |
|
44 |
|
45 |
Consequences |
46 |
------------ |
47 |
So Git relies on the existence of merge commits to detect what has been |
48 |
merged already. Creating all these merge commits is a tough job for a |
49 |
conversion tool (like svn2git) as it would have to distinguish between |
50 |
cases where just a few commist have been cherry-picked over and cases |
51 |
where all previous commits have made it over. |
52 |
|
53 |
So the portage Git history does not have merge commits at these points |
54 |
but plain single-parent commits. |
55 |
|
56 |
|
57 |
Dealing with it |
58 |
=============== |
59 |
|
60 |
The concept |
61 |
----------- |
62 |
So to not get diffs way bigger than needed when merging what we can do |
63 |
is we can manually (and permanently) teach Git what we know more about |
64 |
portage's history. |
65 |
Let's look the case of the prefix branch. |
66 |
|
67 |
The current head on prefix has this log message: |
68 |
|
69 |
[head on prefix] |
70 |
"Merged from trunk -r15842:15843" |
71 |
|
72 |
Looking a few commits back (using gitg or git log) on branch master I |
73 |
find this commit: |
74 |
|
75 |
[commit f52e83b0982c9c18d96757ab55109d43a9873b3f on master] |
76 |
install_qa_check: make sure init.d and conf.d files do not have |
77 |
syntax errors in them #310805 |
78 |
svn path=/main/trunk/; revision=15843 |
79 |
|
80 |
So that's the commit where grobian merged trunk into prefix last time: |
81 |
perfect. |
82 |
|
83 |
|
84 |
Realization |
85 |
----------- |
86 |
How do we teach Git that all that stuff has been merged already? |
87 |
By creating a merge commit with two parents: |
88 |
|
89 |
1) f52e83b0982c9c18d96757ab55109d43a9873b3f |
90 |
2) head on prefix |
91 |
|
92 |
This is how to do it on the shell |
93 |
|
94 |
# Checkout prefix locally |
95 |
git checkout -b prefix overlays-gentoo-org/prefix |
96 |
|
97 |
# Create merge commit manually (_NOT_ something to do usually) |
98 |
MERGE_COMMIT=$(echo \ |
99 |
'Teach Git that trunk@15843 has been merged into prefix' \ |
100 |
| git commit-tree 'prefix^{tree}' -p prefix -p |
101 |
f52e83b0982c9c18d96757ab55109d43a9873b3f) |
102 |
|
103 |
# Inspect result |
104 |
echo ${MERGE_COMMIT} |
105 |
|
106 |
# Move prefix head forward to include that commit |
107 |
git merge ${MERGE_COMMIT} |
108 |
|
109 |
# Inspect what we have done visually |
110 |
gitg |
111 |
|
112 |
That's where we leave the land of dirty hacks and Git's so-called |
113 |
plumbings. We can can continue merging the few remaining commits from |
114 |
here as usual. |
115 |
|
116 |
# Get a feeling for what would be merged |
117 |
# Should list ~10 commits (instead of ~8000 without the hack before) |
118 |
git cherry -v prefix overlays-gentoo-org/master |
119 |
|
120 |
# Merge master into prefix |
121 |
git merge overlays-gentoo-org/master # Fails with conflicts, fine |
122 |
git status |
123 |
git mergetool |
124 |
git commit |
125 |
git push overlays-gentoo-org prefix |
126 |
|
127 |
I hope this mail was helpful to you. |
128 |
|
129 |
|
130 |
|
131 |
Sebastian |