-
Notifications
You must be signed in to change notification settings - Fork 26
Implement exercise T6L2/branch-forward #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
keerthigkaarthik
wants to merge
5
commits into
git-mastery:main
Choose a base branch
from
keerthigkaarthik:exercise-branch-forward
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cb61409
Add branch forward exercise
keerthigkaarthik 88cdc86
Change wrong answer message
keerthigkaarthik d664fd3
Add last empty line
keerthigkaarthik da78786
Apply changes from code review
keerthigkaarthik f54d88a
Apply changes following code review
keerthigkaarthik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| "exercise_name": "branch-forward", | ||
| "tags": [ | ||
| "git-branch", | ||
| "git-merge" | ||
| ], | ||
| "requires_git": true, | ||
| "requires_github": false, | ||
| "base_files": {}, | ||
| "exercise_repo": { | ||
| "repo_type": "local", | ||
| "repo_name": "love-story", | ||
| "repo_title": null, | ||
| "create_fork": null, | ||
| "init": true | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # branch-forward | ||
|
|
||
| You are outlining a story and experimenting with different plotlines. Each version lives on its own branch, and you now need to fold the right storyline back into `main` without cluttering the history. | ||
|
|
||
| ## Learning objectives | ||
|
|
||
| - Identify when a branch can be fast-forward merged | ||
| - Use fast-forward merges to keep the commit graph linear | ||
| - [Fast-forward merges](https://nus-cs2103-ay2526s1.github.io/website/book/gitAndGithub/merge/index.html) | ||
|
|
||
| ## Task | ||
|
|
||
| 1. Review the `with-sally` and `with-ginny` branches. | ||
| 2. Merge only the branch(es) that can be fast-forwarded into `main`. | ||
| 3. Leave other branches (if any) unmerged. | ||
|
|
||
| ## Hints | ||
|
|
||
|
|
||
| <details> | ||
|
|
||
| <summary>Hint 1</summary> | ||
|
|
||
| Ensure you have switched to the destination branch before initiating the merge. | ||
|
|
||
| </details> | ||
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| from exercise_utils.file import append_to_file, create_or_update_file | ||
| from exercise_utils.git import add, checkout, commit | ||
|
|
||
|
|
||
| def setup(verbose: bool = False): | ||
| create_or_update_file( | ||
| "story.txt", | ||
| """ | ||
| Harry was single. | ||
| """, | ||
| ) | ||
| add(["story.txt"], verbose) | ||
| commit("Introduce Harry", verbose) | ||
|
|
||
| append_to_file( | ||
| "story.txt", | ||
| """ | ||
| Harry did not have a family. | ||
| """, | ||
| ) | ||
| add(["story.txt"], verbose) | ||
| commit("Add about family", verbose) | ||
|
|
||
| checkout("with-ginny", True, verbose) | ||
| append_to_file( | ||
| "story.txt", | ||
| """ | ||
| Then he met Ginny. | ||
| """, | ||
| ) | ||
| add(["story.txt"], verbose) | ||
| commit("Add about Ginny", verbose) | ||
|
|
||
| checkout("main", False, verbose) | ||
| create_or_update_file( | ||
| "cast.txt", | ||
| """ | ||
| Harry | ||
| """, | ||
| ) | ||
| add(["cast.txt"], verbose) | ||
| commit("Add cast.txt", verbose) | ||
|
|
||
| checkout("with-sally", True, verbose) | ||
| append_to_file( | ||
| "story.txt", | ||
| """ | ||
| Then he met Sally | ||
| """, | ||
| ) | ||
| add(["story.txt"], verbose) | ||
| commit("Mention Sally", verbose) | ||
|
|
||
| checkout("with-ginny", False, verbose) | ||
| append_to_file( | ||
| "story.txt", | ||
| """ | ||
| Ginny was single too | ||
| """, | ||
| ) | ||
| add(["story.txt"], verbose) | ||
| commit("Mention Ginny is single", verbose) | ||
|
|
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| initialization: | ||
| steps: | ||
| - type: commit | ||
| empty: true | ||
| message: Introduce Harry | ||
| id: start | ||
| - type: commit | ||
| empty: true | ||
| message: Add about family | ||
|
|
||
| - type: branch | ||
| branch-name: with-ginny | ||
| - type: checkout | ||
| branch-name: with-ginny | ||
| - type: commit | ||
| empty: true | ||
| message: Add about Ginny | ||
|
|
||
| - type: checkout | ||
| branch-name: main | ||
| - type: commit | ||
| empty: true | ||
| message: Add cast.txt | ||
|
|
||
| - type: branch | ||
| branch-name: with-sally | ||
| - type: checkout | ||
| branch-name: with-sally | ||
| - type: commit | ||
| empty: true | ||
| message: Mention Sally | ||
|
|
||
| - type: checkout | ||
| branch-name: with-ginny | ||
| - type: commit | ||
| empty: true | ||
| message: Mention Ginny is single | ||
|
|
||
| - type: checkout | ||
| branch-name: main | ||
| - type: merge | ||
| branch-name: with-sally | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| initialization: | ||
| steps: | ||
| - type: commit | ||
| empty: true | ||
| message: Introduce Harry | ||
| id: start | ||
| - type: commit | ||
| empty: true | ||
| message: Add about family | ||
|
|
||
| - type: branch | ||
| branch-name: with-ginny | ||
| - type: checkout | ||
| branch-name: with-ginny | ||
| - type: commit | ||
| empty: true | ||
| message: Add about Ginny | ||
|
|
||
| - type: checkout | ||
| branch-name: main | ||
| - type: commit | ||
| empty: true | ||
| message: Add cast.txt | ||
|
|
||
| - type: branch | ||
| branch-name: with-sally | ||
| - type: checkout | ||
| branch-name: with-sally | ||
| - type: commit | ||
| empty: true | ||
| message: Mention Sally | ||
|
|
||
| - type: checkout | ||
| branch-name: with-ginny | ||
| - type: commit | ||
| empty: true | ||
| message: Mention Ginny is single | ||
|
|
||
| - type: checkout | ||
| branch-name: main | ||
| - type: merge | ||
| branch-name: with-sally | ||
| no-ff: true | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| initialization: | ||
| steps: | ||
| - type: commit | ||
| empty: true | ||
| message: Introduce Harry | ||
| id: start | ||
| - type: commit | ||
| empty: true | ||
| message: Add about family | ||
|
|
||
| - type: branch | ||
| branch-name: with-ginny | ||
| - type: checkout | ||
| branch-name: with-ginny | ||
| - type: commit | ||
| empty: true | ||
| message: Add about Ginny | ||
|
|
||
| - type: checkout | ||
| branch-name: main | ||
| - type: commit | ||
| empty: true | ||
| message: Add cast.txt | ||
|
|
||
| - type: branch | ||
| branch-name: with-sally | ||
| - type: checkout | ||
| branch-name: with-sally | ||
| - type: commit | ||
| empty: true | ||
| message: Mention Sally | ||
|
|
||
| - type: checkout | ||
| branch-name: with-ginny | ||
| - type: commit | ||
| empty: true | ||
| message: Mention Ginny is single | ||
|
|
||
| - type: checkout | ||
| branch-name: main | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| initialization: | ||
| steps: | ||
| - type: commit | ||
| empty: true | ||
| message: Introduce Harry | ||
| id: start | ||
| - type: commit | ||
| empty: true | ||
| message: Add about family | ||
|
|
||
| - type: branch | ||
| branch-name: with-ginny | ||
| - type: checkout | ||
| branch-name: with-ginny | ||
| - type: commit | ||
| empty: true | ||
| message: Add about Ginny | ||
|
|
||
| - type: checkout | ||
| branch-name: main | ||
| - type: commit | ||
| empty: true | ||
| message: Add cast.txt | ||
|
|
||
| - type: branch | ||
| branch-name: with-sally | ||
| - type: checkout | ||
| branch-name: with-sally | ||
| - type: commit | ||
| empty: true | ||
| message: Mention Sally | ||
|
|
||
| - type: checkout | ||
| branch-name: with-ginny | ||
| - type: commit | ||
| empty: true | ||
| message: Mention Ginny is single | ||
|
|
||
| - type: checkout | ||
| branch-name: main | ||
| - type: branch | ||
| branch-name: with-ron | ||
| - type: checkout | ||
| branch-name: with-ron | ||
| - type: commit | ||
| empty: true | ||
| message: Mention Ron | ||
|
|
||
| - type: checkout | ||
| branch-name: main | ||
| - type: merge | ||
| branch-name: with-ron | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| initialization: | ||
| steps: | ||
| - type: commit | ||
| empty: true | ||
| message: Introduce Harry | ||
| id: start | ||
| - type: commit | ||
| empty: true | ||
| message: Add about family | ||
|
|
||
| - type: branch | ||
| branch-name: with-ginny | ||
| - type: checkout | ||
| branch-name: with-ginny | ||
| - type: commit | ||
| empty: true | ||
| message: Add about Ginny | ||
|
|
||
| - type: checkout | ||
| branch-name: main | ||
| - type: commit | ||
| empty: true | ||
| message: Add cast.txt | ||
|
|
||
| - type: branch | ||
| branch-name: with-sally | ||
| - type: checkout | ||
| branch-name: with-sally | ||
| - type: commit | ||
| empty: true | ||
| message: Mention Sally | ||
|
|
||
| - type: checkout | ||
| branch-name: with-ginny | ||
| - type: commit | ||
| empty: true | ||
| message: Mention Ginny is single | ||
|
|
||
| - type: checkout | ||
| branch-name: main | ||
| - type: merge | ||
| branch-name: with-ginny | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| initialization: | ||
| steps: | ||
| - type: commit | ||
| empty: true | ||
| message: Introduce Harry | ||
| id: start | ||
| - type: commit | ||
| empty: true | ||
| message: Add about family | ||
|
|
||
| - type: branch | ||
| branch-name: with-ginny | ||
| - type: checkout | ||
| branch-name: with-ginny | ||
| - type: commit | ||
| empty: true | ||
| message: Add about Ginny | ||
|
|
||
| - type: checkout | ||
| branch-name: main | ||
| - type: commit | ||
| empty: true | ||
| message: Add cast.txt | ||
|
|
||
| - type: branch | ||
| branch-name: with-sally | ||
| - type: checkout | ||
| branch-name: with-sally | ||
| - type: commit | ||
| empty: true | ||
| message: Mention Sally | ||
|
|
||
| - type: checkout | ||
| branch-name: with-ginny | ||
| - type: commit | ||
| empty: true | ||
| message: Mention Ginny is single | ||
|
|
||
| - type: checkout | ||
| branch-name: main | ||
| - type: bash | ||
| runs: | | ||
| git merge with-ginny | ||
| git reset --hard 'HEAD^' | ||
| git merge with-sally |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.