-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubtrees.Rmd
143 lines (96 loc) · 5.75 KB
/
subtrees.Rmd
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# Subtrees using Smartgit {#subtrees}
## NOTE:
This chapter is basically a "copy and paste" document from the original Smartgit
page. The value added is the images that illustrate what is written.
Subtrees is a way to integrate other repositories into a, more general
repository. Each repository that is added to the main repository is a "subtree"
and will be stored as a sub-folder into the root directory of the main
repository.
## **Subtrees in the UI**
Refs belonging to subtrees will be denoted in the **Branches** view by a
*folder*-symbol.
![subtree_brach](img/subtree_branch.png)
Local subtrees will show up in the **Subtrees** category. The root commits of a
subtree will be denoted by a *folder*-symbol in the Log **Graph**.
![subtree_graph](img/subtree_folder.png)
## **Basic Subtree operations**
To add a new subtree, select the root directory of the repository in the
**Repositories** view and invoke **Remote -\> Subtree -\>Add**.
![add_subtree](img/add_subtree.png)
If you're adding several subtrees to the main repo, rename the remote subtree
when you're adding a new subtree
![change_name](img/change_name_of_remote_subtree.png)
To fetch new (remote) changes from the subtree repository, select the subtree
remote in the **Branches** view and invoke **Pull** from the context menu.
![subtree_pull1](img/subtree_pull1.png)
To merge (or cherry-pick) a subtree use the **Merge** (or **Cherry-Pick**)
command. SmartGit will understand whether the source commit is a subtree and in
this case perform a subtree merge (or cherry-pick).
![subtree_merge](img/subtree_merge.png)
To push commits back to a subtree, select the (remote) subtree branch in the
**Branches** view and invoke **Remote\|Subtree\|Push**. Pushing a subtree
involves splitting changes back from main repository to subtree repository (more
details can be found below).
To reset your main repository to a certain subtree, first **Check Out** the
branch which should be reset. Then, in the **Branches** view, select the subtree
branch to which your main repository should be reset to and invoke
**Subtree\|Reset** from the context menu.
#### **Note**
> If there are already existing subtrees in your main repository you will have
> to add corresponding remotes for these subtrees using **Remote\|Add**.
## **Synchronizing changes back to the subtree repository**
There are two ways of pushing changes to the remote.
### Using Push
1. **Check Out** the the repository's branch which will be pushed to a specific
subtree branch.
2. Make sure your changes are staged and commited in the branch of your choice
in the **main** repository
3. In the **Branches** view, select the subtree branch to which the changes
should be pushed and invoke **Subtree-\>Push**from the context menu.
![](img/subtree_push1.png)Use the prefix to specify that this change is
coming from a repo that is using the modifying repo as a subtree
![](img/subtree_push2.png)
4. The commits created by the *Split*-command will be written to the
**Subtree-Branch to update**. If you have selected a remote subtree branch,
you will have to select **Subtree-Branch to update** or enter the name of a
new branch there; in either case the selected branch will then be
updated/created. In this case I decided to implement the changes in the
*dev* branch of the subtree. Since that branch does not exist it won't be
created
### Using Split
After having applied changes to files in your main repository which actually
belong to a subtree repository, you can "synchronize" these changes back to the
subtree repository using the **Split** command:
1. **Check Out** the main repository's branch which should be split back.
2. Make sure your changes are staged and commited in the branch of your choice
in the **main** repository
3. In the **Branches** view, select the subtree branch to which the changes
should be split back and invoke **Subtree\|Split** from the context menu.
The commits created by the *Split*-command will be written to the
**Subtree-Branch to update**. If you have selected a remote subtree branch,
you will have to select **Subtree-Branch to update** or enter the name of a
new branch there; in either case the selected branch will then be
updated/created. In this case I decided to implement the changes in the
*dev* branch of the subtree. Since that branch does not exist it won't be
created
![subtree_split](img/subtree_split.png)
#### **Note**
> SmartGit will not actually split changes back to this particular *branch*
> but the branch selection serves primarily to identify to which *subtree*
> the changes should be split back. The underlying Git command will then
> detect the appropriate subtree commits onto which the new commits will be
> split back.
4. To push changes back to your remote subtree repository, tracking between the
local subtree branch which has just been updated/created in step 2 and the
remote subtree branch has to be set up. This can optionally be done as part
of the **Add** wizard or you can do it manually:
1. In the **Branches** view, select both the local and remote subtree
branch and invoke **Set Tracked Branch** from the context menu.
2. The **Branches** will now denote ahead/behind commits for the local
subtree branch.
3. Verify these ahead/behind commits also in the **Graph**.
4. Push back the subtree commits by selecting the local subtree branch in
the **Branches** view and invoking **Push** from the context menu.
## Information
- [Smartgit](https://docs.syntevo.com/SmartGit/Latest/Subtrees.html#:~:text=SmartGit%20will%20understand%20whether%20the,invoke%20Remote%7CSubtree%7CPush.)
- [viz](https://opensource.com/article/20/5/git-submodules-subtrees)