- ๐ฉ๐พโ๐ป software engineer
- ๐คซ introvert
- ๐๐พ shuffle dancer
- ๐ she/her, they/them
fun-git's Introduction
fun-git's People
fun-git's Issues
rebasing
In which Keziyah learns what a rebase is, and how it can get her out of this situation:
I'm working on a feature branch, my-feature-1
, and while it's waiting to be merged, I need to open another branch that depends on it. So while in my-feature
, I git checkout -b my-feature-2
.
I work on my part 2 branch, meanwhile my-feature
has since been merged, as well as a few other branches that other people have worked on. How do I get my-feature-2
into master without messing things up?
What is rebasing
Rebasing and merging have the same end goal. Taking feature branches and integrating them into master. But they do it in different ways. Merges create a new merge commit on master.
Rebasing takes you feature commits and moves them on top of the master branch. It rewrites history by erasing your feature branch commits and just putting your feature on top of master.
So, like, what do I do
According to this Stack Overflow answer, I should do something like this:
- After opening a new branch
my-feature-2
frommy-feature-1
- Anytime
my-feature-1
changes during code review, rebasemy-feature-2
on it.
... commit something onto my-feature-1 ... git checkout my-feature-2 git rebase my-feature-1
This will take my feature 2 commits and put them on top of what i've done from feature 1, making my feature 2 commit history appear to start right after my latest changes to feature 1. - When feature 1 is merged, rebase feature 1 onto it again:
git checkout master git pull origin master git checkout feature-2 git rebase --onto master feature-1 feature-2
This makes it so that my feature-2 branch is branched off master.
Task
I'm going to try this.
- Create a feature-1 branch, make some commits
- Create a feature-2 branch off feature 1
- Create other branches and merge them into master before feature-1 is merged
- Merge feature-1 and make it so that feature-2 is branched off master
Results
- I created 4 branches: features 1-4. Feature 2 is branched off Feature 1.
- I merged feature-3 and feature-4 into master.
- I went into feature-1 and did
git merge master
- Since feature-1 has changed, I have to rebase feature-2 on it. So I checked out feature-2 and did
git-rebase feature-1
Now my feature-2 looks like it began after the latest master merge into feature-1.
Before rebasing:
Feature 2 history:
Feature 1 history:
After rebasing:
Then I merged feature-1 into master.
Now to clean up the difference between feature-2
and master. There are more changed files than necessary. The ReadMe, for example, is exactly how it is in master. That's why we need to rebase.
So while in feature-2, I did git rebase --onto master feature-1 feature-2
Changed file list before rebase:
After rebase:
Ok, never mind, it didn't work. The changed files in feature-2 are still the same.
Second try
- Created 3 branches. f-1, f-2, and f-3. f-2 depends on f-1.
- Merged f-3 into master.
- did
git rebase master f-1
while in branch f-1. so that my f-1 commits come after the latest master. - Merged f-1 into master
- git rebase master f-1
- git rebase --onto feature1 f-1@{1} f-2
Source
I think this worked better. Woohoo!
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.