![]() ![]() It also added a lot of text, which tells you which commands you can use during the interactive rebase. Here we will only use a few commands to make the process as easy as possible.Īs you can see Git already listed all your commits, which are based on the commit you picked in the command, in reverse chronological order. Vim is a very powerful editor, which takes some practice to master. Luckily Git will automatically show more characters of the hash, if necessary.Īfter you typed the command Terminal will send you to an editor: Vim. Note: You might need more than 7 characters to identify your commit, depending on the size of your project. The “-i” tells Git that we want to do an interactive rebase, while the “2d4163c” tells Git that we want to do the interactive rebase based on the commit with this commit id. Let’s start our first interactive rebase session by typing the following: git rebase -i 2d4163c The most obvious issue is probably the bug fix commit “fix: spelling eroor on home page and add logo”, which talks about fixing a spelling error in the code but contains a spelling error in its own commit message. If you take a closer look at the commit messages you can see that some of the commits need improvement. For each commit, you can see its commit id, a hash containing 7+ characters, and the actual commit message. This command will show all the commits on the current branch, with each of them summarized on a single line. To get a brief overview type the following: git log -oneline Please note that the intent of the demo repository is to illustrate interactive rebasing and not to actually provide meaningful content.īefore we can actually start improving our commits using the interactive rebase, we first need to take a look at the commit history of the Git repository. Now clone the project and navigate inside: git clone If you would like to work on it in your home directory navigate to it first by typing: cd ~ Open the terminal application and navigate to a location, where you would like to work on the project. If you want to follow the exact steps described in this tutorial, you can clone the demo Git repository as described below. If you’re using Sourcetree, you can try this tutorial:Īll the commands are executed in the Terminal app on a Mac, commands on another platform might be slightly different. Nevertheless, if you think Git’s interactive rebase is an interesting feature, but you don’t want to use the command line, you can also use your Git GUI client. ![]() But fear not, it’s fairly intuitive and I will explain the process step by step. We will see how to use the interactive rebase feature on the command line. Therefore, it is highly recommended to only use the interactive rebase function on your local commit history, before you push it to the remote. Using interactive rebase on your commits does not edit them, but creates new commits instead. Anyone, including yourself, who will have to look through the old commits at some point in the future will be grateful for that. Having a clean Git commit history sounds great, but what is the benefit of investing the extra effort? Well, besides the aesthetics you get a semantically correct and meaningful commit history, which will be easier to understand. Edit your commit to add or remove changes to/from it Squash two or more commits into a single one Split one commit into two or more commits In this tutorial article, I will show how to use interactive rebase to: You may want to do this if you branched off your branch from master a while ago and now want to base your branch on the current state of the master branch to discover possible conflicts and issues before the actual merge back into the master branch.Īn interactive rebase, however, let’s you clean up your commit history from flaws and silly oversights, which you often only spot in hindsight. Maybe you have heard of Git rebase before and you’re wondering what the difference to an interactive rebase is.Ī normal rebase let’s you reapply the commits of your branch on a different base commit. This is where Git’s interactive rebase feature comes to the rescue. ![]() When looking at them after a while we often realize that we have a spelling error in our commit message, it took us several commits to correctly implement a certain feature or that we mixed changes from a feature and a bug fix in the same commit. Nevertheless, these commits are often not as clean and perfect as we wish they would be. Every time we are satisfied with the state of a logical chunk of code, we create a commit containing our changes. Luckily, with version control systems like Git, we can decide ourselves when we are happy enough with our code to share with our team or the rest of the world. During development, we frequently have commented or unused chunks of code, spelling errors, or even logic errors in our code. Software development is often a messy process. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |