project created
This commit is contained in:
@@ -1,2 +1,144 @@
|
||||
# Advanced-git
|
||||
This repo is a workshop assignment to practice conflict resolvation in git
|
||||
|
||||
# 🚀 WS 11 - Advanced Git & Github
|
||||
|
||||
---
|
||||
|
||||
## 📖 Overview
|
||||
In this assignment, you will simulate multiple developers working on the same project using different Git branches.
|
||||
You will create parallel development scenarios, encounter merge conflicts, and practice resolving them using Git. By the end, you should feel confident handling common conflict situations that occur in real-world software development.
|
||||
|
||||
---
|
||||
|
||||
## Prerequisites
|
||||
- Git installed
|
||||
- A GitHub account
|
||||
- Java SDK 25
|
||||
- Maven
|
||||
---
|
||||
## 🎯 Objectives
|
||||
By completing this assignment, you will:
|
||||
- Become comfortable creating and switching between Git branches
|
||||
- Learn how to resolve same-line content conflicts
|
||||
- Practice resolving:
|
||||
- Modify/modify conflicts
|
||||
- Modify/delete conflicts
|
||||
- Rename conflicts
|
||||
- Understand how Git tracks file changes across branches
|
||||
|
||||
---
|
||||
## Project Structure
|
||||
- **Calculator.java:** Interface which defines calculator methods
|
||||
- **BasicCalculator.java:** Implements Calculator with basic arithmetic
|
||||
- **MathHelper.java:** Static utility methods (multiply, square, max)
|
||||
- **ReportGenerator.java:** Uses Calculator and MathHelper to produce formatted output
|
||||
---
|
||||
|
||||
## 📦 Task 1 – Refactoring Conflict
|
||||
|
||||
### Scenario:
|
||||
Two developers are working in parallel:<br>
|
||||
- Developer A refactors the code by renaming a method.
|
||||
- Developer B continues developing a new feature using the old method name.
|
||||
|
||||
When their work is merged, a conflict will occur.
|
||||
|
||||
1. First fork & clone the repository and create develop branch:
|
||||
|
||||
```
|
||||
git clone https://github.com/<your-username>/conflict-demo.git
|
||||
git checkout -b develop
|
||||
```
|
||||
|
||||
2. Create two feature branches(feature/refactor-multiply & feature/change-multiply). we will assume they are 2 separate developers working on project. One of them will refactor project by renaming a method across whole project, while other developer is still working with old name.
|
||||
```
|
||||
git checkout develop
|
||||
git checkout -b feature/refactor-multiply
|
||||
git checkout develop
|
||||
git checkout -b feature/change-multiply
|
||||
```
|
||||
|
||||
3. From feature/refactor-multiply branch, rename "multiply" method to "product" everywhere.
|
||||
```
|
||||
git checkout feature/refactor-multiply
|
||||
# TODO: rename method "multiply" to "product" in Calculator, BasicCalculator, MathHelper and ReportGenerator
|
||||
git add .
|
||||
git commit -m "refactor: renamed multiply to product"
|
||||
git checkout develop
|
||||
git merge feature/refactor-multiply
|
||||
```
|
||||
|
||||
4. From feature/change-multiply branch, change the body of multiply method
|
||||
```
|
||||
git checkout feature/change-multiply
|
||||
# TODO: change the body of MathHelper.multiply (e.g., loop-based multiplication)
|
||||
git add .
|
||||
git commit -m "multiply method body changed"
|
||||
git checkout develop
|
||||
git merge feature/change-multiply # CONFLICT
|
||||
```
|
||||
|
||||
5. Resolve the conflict
|
||||
```
|
||||
# TODO: Open conflicted file(s), decide to keep the `product` name, and apply the new logic.
|
||||
git add .
|
||||
git commit -m "conflict resolved: keep rename, apply new multiply logic"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📦 Task 2 – Deletion Conflict
|
||||
|
||||
### Scenario
|
||||
|
||||
Two developers are working on the same interface:
|
||||
|
||||
- Developer A decides that the `Calculator` interface is no longer needed and deletes it from the project.
|
||||
- Developer B is still working on the interface and adds a new method to it.
|
||||
|
||||
When the branches are merged, Git will detect a **modify/delete conflict** because one branch deleted the file while the other modified it.
|
||||
|
||||
1. Create Two branches called feature/remove-calculator and feature/add-method-to-interface. We will delete interface file in project in first branch, while second one is working on it. Then we will solve conflict that happends in merging.
|
||||
```
|
||||
git checkout develop
|
||||
git checkout -b feature/remove-calculator
|
||||
git checkout develop
|
||||
git checkout -b feature/add-method-to-interface
|
||||
```
|
||||
|
||||
2. From feature/remove-calculator branch, delete interface file completely:
|
||||
```
|
||||
git checkout feature/remove-calculator
|
||||
git rm src/main/java/com/ap/Calculator.java
|
||||
git commit -m "remove Calculator interface"
|
||||
git checkout develop
|
||||
git merge feature/remove-calculator
|
||||
```
|
||||
|
||||
3. From feature/add-method-to-interface add method to deleted interface
|
||||
```
|
||||
git checkout feature/add-method-to-interface
|
||||
# TODO: add "double calculateArea(double,double)" to Calculator, implement in BasicCalculator
|
||||
git add .
|
||||
git commit -m "add calculateArea() method"
|
||||
git checkout develop
|
||||
git merge feature/add-method-to-interface # CONFLICT
|
||||
```
|
||||
|
||||
4. Resolve
|
||||
- Keep the `Calculator` interface.
|
||||
- Restore the deleted file.
|
||||
- Add the new `calculateArea()` method to the interface.
|
||||
```
|
||||
git add .
|
||||
git commit -m "resolved: Restored deleted interface and added calculateArea "
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📤 Deliverable
|
||||
- Push your branches with all merge commits. <br>
|
||||
- Show output of your git history:
|
||||
```
|
||||
git log --oneline --graph --all --decorate
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user