2.7 KiB
branches
- suppose there is a problem
if i have to make multiple versions of a page and thats where version control like git helps and i use multiple branch for multiple versions of my page.
so lets say i create a page which has
1. blue background
2. red foreground
now i have created a branch v2 which is branched from this earlier master branch
now this page have
1. black bg
2. white fg
and few more changes to be done
3. rectangle div at center of screen
and now my boss saw my both version and preferred version 1 ie master branch but master branch is lacking 3rd change
so how do i get changes from master branch and also new changes from v2 and create another branch so it have
1. master branch properies ie blue bg and red fg and 3rd property ie rectangle div at center of screen
then maybe this will help https://joseewouters.nl/blog/cherry-picking-with-git-in-your-terminal/
if editing 1st and 2nd property has separate commit named edit colors and adding rectangle div have commit named adding container then go to v2 and craete a branch from this git checkout -b v3
Now using rebase
git rebase -i master
this will be the output
pick a1b2c3 edit colors
pick d4e5f6 adding container
change to
edit a1b2c3 edit colors
pick d4e5f6 adding container
now when u save this, it will stop the git to that edit colors commit
now do this
git reset HEAD~ ( move back to parent commit of HEAD )
as we want to actually dont want edit colors thing to be taken place. as the edit colors commit changes has been applied here so we need to move back to parent commit of HEAD
now make changes manually here as we r just editing changes of one commit without dealing with others
now add commits
git add file.txt
git commit -m "Add center div container"
there can be more commits after this and we may not need to add all of them
then just do
git rebase --continue
to abort all this in between in case things can get messy use
git rebase --abort
above steps have a manual appraoch too bcz changes to be made before staging is still to be done manually.
more git rebase words
Keep commit : pick
Modify / split commit : edit
Rename commit : reword
Combine commits : squash
Auto-combine commits : fixup
Remove commit : drop
Run command : exec
in vscode accept combination to merge changes in merge editor or just do it manually after dropping one of commit
and maybe this might help after forking it, keep one branch unchanged to always follow upstream. Periodically sync the fork so the upstream branch is up to date. Periodically merge changes you want to your other branches
also git rebase implies adding your commits after the other guys' git merge would add their commits after yours