AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Rebase git8/5/2023 ![]() ![]() So, we create a new branch from the master branch, let’s call it a ‘feature branch. Now, we don’t want to touch the master branch code, we want to copy the code of the master branch to a new place, where we can experiment or change the code. So, the website we showed you above is the master branch. By default, all your code is stored on a master branch. So, in git to isolate different versions of code we have branches. Make changes in the code, and then once the changes are finalised, you will replace the code in the main folder right? Let us understand how we can do the above thing in git. So, what do you do? Ideally, you will copy the code of this website in a new folder. But if you are changing the code, you do not want the changes to be reflected in the main website which is deployed. For this, you will have to change the code of the website. You want to add more features to this website. The website looks something like this.įig 3: Sample example of the website before changes Let us take an example to understand this, Let’s say you have a website that is currently running. So whenever we make any change, it generates a new commit.įig 2: The changes made in the repository will be saved as a new commit with a new commit id What is a Branch?Ī Branch is a representation of different isolated versions of code. These changes in git will be saved as another commit with another commit-id 14343. Now let us say we have made some changes to the code by adding another python file. Each commit has a commit-id, let it be 1234 in our case. These four python files will be saved inside a commit. In Fig: 1, Let us assume that we have four python files. Let us take an example and discuss in brief from the diagram shown below:įig 1: The changes made are saved in a commit What is a Commit?Ĭommit is defined as the location where the code and its changes are stored. Let’s understand these two terms respectively. How can Git Rebase and Git Merge be used together?įor understanding the working of git, we need to understand the two fundamental concepts in git which is git commit and git branch. ![]() Sectioning and Rebasing a Branch #Īs mentioned earlier, the command presented above allows not only to rebase a branch to a new parent but also to section it - to extract only a part of it.So, the following are the topics covered in this blog: Note: This post will not delve into the git rebase command. After the rebase, HEAD will end up pointing to the rewritten, whether it was explicitly provided or not (in the latter case, HEAD will point to “ HEAD'”). Also, when successfully executing git rebase, a piece of the commit history will have been rewritten - a group of existing commits will get new SHA-1 hashes. Remember that a branch is just a pointer to a commit - the last one in that branch. (Don’t worry, this will be shown in an example in the following section.) Put in a different way, the resulting branch will go from to, exclusive of the former and inclusive of the latter. To those familiar with git rebase, its basic syntaxis is the following: 1 In this post, I will present a solution for this problem. However, it lacked the answer as to how to recover the detached HEAD pointing to the commits that form the section of the branch that was cut. Post - it provides an answer on how to cut a section of a branch and rebase it onto master. I looked for solutions and I found this extremely helpful blog ![]() ![]() If you’ve never got a problem like this in Git, don’t worry - you will. When doing so, however, I wanted to keep the previous branch and make the new one, a detached HEAD by default, into a branch I can work on. That is, I wanted to rebase only a portion of my branch onto a different parent commit of master than the current one. I was recently facing a Git situation in which I had to rebase a section of a branch onto a specific commit of master. ![]()
0 Comments
Read More
Leave a Reply. |