Skip to content

Commit ea4fb32

Browse files
authored
add rebase
1 parent fffa70b commit ea4fb32

File tree

1 file changed

+136
-0
lines changed

1 file changed

+136
-0
lines changed

k8s-contrib.md

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,139 @@ aimee@aimee-lemur:~/Dev/git/github.com/aimeeu/k8s/sigdocs/website$ git branch
154154
update115toHugo572
155155
156156
```
157+
158+
#### Merge conflicts and rebasing
159+
160+
{{< note >}}
161+
For more information, see [Git Branching - Basic Branching and Merging](https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging#_basic_merge_conflicts), [Advanced Merging](https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging), or ask in the `#sig-docs` Slack channel for help.
162+
{{< /note >}}
163+
164+
If another contributor commits changes to the same file in another PR, it can create a merge conflict. You must resolve all merge conflicts in your PR.
165+
166+
1. Update your fork and rebase your local branch:
167+
168+
```bash
169+
git fetch origin
170+
git rebase origin/<your-branch-name>
171+
```
172+
173+
Then force-push the changes to your fork:
174+
175+
```bash
176+
git push --force-with-lease origin <your-branch-name>
177+
```
178+
179+
2. Fetch changes from `kubernetes/website`'s `upstream/master` and rebase your branch:
180+
181+
```bash
182+
git fetch upstream
183+
git rebase upstream/master
184+
```
185+
186+
3. Inspect the results of the rebase:
187+
188+
```bash
189+
git status
190+
```
191+
192+
This results in a number of files marked as conflicted.
193+
194+
4. Open each conflicted file and look for the conflict markers: `>>>`, `<<<`, and `===`. Resolve the conflict and delete the conflict marker.
195+
196+
{{< note >}}
197+
For more information, see [How conflicts are presented](https://git-scm.com/docs/git-merge#_how_conflicts_are_presented).
198+
{{< /note >}}
199+
200+
5. Add the files to the changeset:
201+
202+
```bash
203+
git add <filename>
204+
```
205+
6. Continue the rebase:
206+
207+
```bash
208+
git rebase --continue
209+
```
210+
211+
7. Repeat steps 2 to 5 as needed.
212+
213+
After applying all commits, the `git status` command shows that the rebase is complete.
214+
215+
8. Force-push the branch to your fork:
216+
217+
```bash
218+
git push --force-with-lease origin <your-branch-name>
219+
```
220+
221+
The pull request no longer shows any conflicts.
222+
223+
224+
### Squashing commits
225+
226+
{{< note >}}
227+
For more information, see [Git Tools - Rewriting History](https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History), or ask in the `#sig-docs` Slack channel for help.
228+
{{< /note >}}
229+
230+
If your PR has multiple commits, you must squash them into a single commit before merging your PR. You can check the number of commits on your PR's **Commits** tab or by running the `git log` command locally.
231+
232+
{{< note >}}
233+
This topic assumes `vim` as the command line text editor.
234+
{{< /note >}}
235+
236+
1. Start an interactive rebase:
237+
238+
```bash
239+
git rebase -i HEAD~<number_of_commits_in_branch>
240+
```
241+
242+
Squashing commits is a form of rebasing. The `-i` switch tells git you want to rebase interactively. `HEAD~<number_of_commits_in_branch` indicates how many commits to look at for the rebase.
243+
244+
Output is similar to:
245+
246+
```bash
247+
pick d875112ca Original commit
248+
pick 4fa167b80 Address feedback 1
249+
pick 7d54e15ee Address feedback 2
250+
251+
# Rebase 3d18sf680..7d54e15ee onto 3d183f680 (3 commands)
252+
253+
...
254+
255+
# These lines can be re-ordered; they are executed from top to bottom.
256+
```
257+
258+
The first section of the output lists the commits in the rebase. The second section lists the options for each commit. Changing the word `pick` changes the status of the commit once the rebase is complete.
259+
260+
For the purposes of rebasing, focus on `squash` and `pick`.
261+
262+
{{< note >}}
263+
For more information, see [Interactive Mode](https://git-scm.com/docs/git-rebase#_interactive_mode).
264+
{{< /note >}}
265+
266+
2. Start editing the file.
267+
268+
Change the original text:
269+
270+
```bash
271+
pick d875112ca Original commit
272+
pick 4fa167b80 Address feedback 1
273+
pick 7d54e15ee Address feedback 2
274+
```
275+
276+
To:
277+
278+
```bash
279+
pick d875112ca Original commit
280+
squash 4fa167b80 Address feedback 1
281+
squash 7d54e15ee Address feedback 2
282+
```
283+
284+
This squashes commits `4fa167b80 Address feedback 1` and `7d54e15ee Address feedback 2` into `d875112ca Original commit`, leaving only `d875112ca Original commit` as a part of the timeline.
285+
286+
3. Save and exit your file.
287+
288+
4. Push your squashed commit:
289+
290+
```bash
291+
git push --force-with-lease origin <branch_name>
292+
```

0 commit comments

Comments
 (0)