You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/branches-exercises.md
+41-1Lines changed: 41 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -124,5 +124,45 @@ Start by making sure you are in the directory `git_materials/5.branches/4.rebase
124
124
$ git log --oneline --abbrev-commit --all --graph
125
125
```
126
126
127
-
## 5.
127
+
## 5. Rebase two local branches resulting in a conflict
128
+
129
+
!!! note
130
+
131
+
This exercise will again let you rebase two branches, using the command `git rebase`. In this case the rebase will fail.
132
+
133
+
**Situation:** In the branch "metric" we change the recipe to use the metric system for measurements. Then we switch back to the "master" branch and **add some coffee** to that version of the recipe.
134
+
135
+
Start by making sure you are in the directory `git_materials/5.branches/5.rebase-bad/recipes`.
136
+
137
+
1. Check status and history with `git status` and `git graph` or `git log` first, including with the following flags to `git log`:
138
+
139
+
```
140
+
$ git log --oneline --abbrev-commit --all --graph
141
+
```
142
+
2. Try to rebase the "master" branch to the "metric" branch using the `git rebase` command and see that a conflict happens.
143
+
144
+
NOTE: Remember to check with `git branch` to find out if you are on the right branch before trying to rebase.
145
+
146
+
You will get an error more or less similar to this:
147
+
148
+
```
149
+
$ git rebase master
150
+
First, rewinding head to replay your work on top of it...
151
+
Applying: Change from imperial units to metric units.
152
+
Using index info to reconstruct a base tree...
153
+
M cakerecipe.txt
154
+
Falling back to patching base and 3-way merge...
155
+
Auto-merging cakerecipe.txt
156
+
CONFLICT (content): Merge conflict in cakerecipe.txt
157
+
error: Failed to merge in the changes.
158
+
Patch failed at 0001 Change from imperial units to metric units.
159
+
Use 'git am --show-current-patch' to see the failed patch
160
+
161
+
Resolve all conflicts manually, mark them as resolved with
162
+
"git add/rm <conflicted_files>", then run "git rebase --continue".
163
+
You can instead skip this commit: run "git rebase --skip".
164
+
To abort and get back to the state before "git rebase", run "git rebase --abort".
165
+
```
166
+
<br>
167
+
3. Use `git log` (with the above flags) or `git graph`and `git status` to see where the problems are. See if you can fix the conflict and then reattempt the rebase.
0 commit comments