Created
April 18, 2023 21:40
-
-
Save brinyemp4/25774282e63d477dcc2b3621b174f77c to your computer and use it in GitHub Desktop.
A usecase of rebase with solution
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
Question: Let's say I have a stable project on `master` branch having commit message "A-message", my 2 team members are working on 2 individual features - `useragent` (commit message "B-message") & `base64` (commit message "C-message"). They both have raised 2 different pull requests and I have to take care of both of them, then following solution is helpful. | |
Challenge is how to set commit history in such manner that over `master` branch, I will have the following sequence. | |
``` | |
C-message | |
B-message | |
A-message | |
``` | |
Solution: | |
`git clone <challenge-url>` | |
`git checkout master` | |
`git rebase feature/useragent master` | |
(This will add feature/useragent's commit B-message on the top of A-message on master branch.) | |
----- | |
[For the safe side, I push to my-origin from cloned challenge url] | |
`git remote add my-origin <my-solution-url>` | |
git push my-origin master | |
(my-origin branch will have following sequence. | |
``` | |
B-message | |
A-message | |
```) | |
----- | |
`git checkout feature/useragent` | |
`git rebase feature/base64 feature/useragent` | |
(Note: your branch has been switched to feature/base64 from feature/useragent.) | |
Then fix the conflicts [Don't forget to set correct code] & continue rebase | |
`git rebase --continue` | |
It will prompt you to enter commit message [I kept it as it is]. | |
By now, you'll have the correct message sequence but within `base64` branch but we need it within `master` branch, so we have to do the following. | |
`git rebase feature/base64 master` | |
Check your log to see the sequence, it should look like as follow: | |
``` | |
C-message | |
B-message | |
A-message | |
``` | |
----DONE---- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment