Sure, here's a simple simulation of how a trunk-based development might work with 5 students working on a simple Python application. We'll assume that each student is working on a different feature of the application.
-
Initial Setup: The instructor (or one of the students) creates a new repository on GitHub for the Python application. This repository contains the main branch (trunk).
-
Clone the Repository: Each student clones the repository to their local machine.
git clone https://github.com/instructor/python-app.git
-
Create a Short-Lived Feature Branch: Each student creates a new branch for their feature from the main branch.
git checkout -b feature-1 # Each student should replace "feature-1" with the name of their feature
-
Develop the Feature: Each student writes the code for their feature. They commit their changes regularly and push them to their feature branch on GitHub.
git add . git commit -m "Progress on feature" git push origin feature-1 # Replace "feature-1" with the name of the feature
-
Pull Request: Once a student has finished their feature, they create a pull request on GitHub. This is a request to merge their feature branch into the main branch.
-
Code Review: The instructor (or other students) review the code in the pull request. They may suggest changes or improvements.
-
Merge the Feature: Once the code has been reviewed and approved, it's merged into the main branch. The feature branch can then be deleted.
-
Update the Local Main Branch: After a feature has been merged into the main branch, all students should update their local main branch to get the latest changes.
git checkout main git pull origin main
-
Repeat: Steps 3-8 are repeated for each new feature.
This process ensures that all changes are integrated into the main branch frequently and that the main branch always contains a working version of the application. It also encourages collaboration and code review, as all changes are reviewed before they're merged into the main branch.
To roll back changes from the main branch (also known as trunk) in Git, you can use the
git revert
command. This command creates a new commit that undoes the changes made in a specific commit.Here's a step-by-step guide:
First, you need to find the commit hash of the commit you want to revert. You can do this by using the
git log
command, which will display a list of all the commits. The commit hash is the long string of numbers and letters next to each commit.Once you have the commit hash, you can use the
git revert
command followed by the commit hash to create a new commit that undoes the changes made in that commit.Here's how you can do it:
Remember to replace
5f57d5b1b3e7a9a378824fdd73a9f6c5a9909632
with the hash of the commit you want to revert.