![]() ![]() ![]() Quite practically, all the available action keywords are documented at the bottom of this window - so there’s no need to remember anything by heart! In our case, we want to reword the commit (which means we’d like to change the commit message, but leave the rest of the commit as is). We only mark up the respective line with an “action keyword”. Right after executing this command, your favorite editor will open up and present the list of commits you just selected (by providing a base commit).Īs a reminder: although you might be tempted to do so, we do not change the commit message here. Since we have to (at least) go back to the parent of our “bad apple” commit, we’re starting our session at HEAD~3 (three commits behind the HEAD commit, which is the one that’s titled “Change headlines …”): $ git rebase -i HEAD~3 Our first step is to determine the base commit for starting this interactive rebase session. You don’t need Tower to follow along in this tutorial.įor our example, let’s say that we’d like to edit the message of the commit currently titled “Optimize markup structure in index…” Note: For a better overview and clearer visualization, I’m using the Tower Git desktop client in some of my screenshots. Below is an image of a bad commit message that needs to be corrected. Let’s take a look at a concrete scenario. ![]() For any commit older than that, we have to use interactive rebase! You might be aware that git commit -amend also allows you to change a commit’s message - but only if it’s the very latest commit. One of the very popular use cases of interactive rebase is that you can edit an old commit message after the fact. ![]() With this theoretical overview out of the way, let’s dive into some practical cases together! I’ll demonstrate this point in practice shortly! Here, we are only going to tell Git what we want to do - but not make the actual change. Don’t make your actual changes in this editor window! Although you might be itching to simply go ahead and change the commit message in this editor window (after all, that’s what we actually want to do …), you have to show some patience.Don’t worry: your Git repository is fit as a fiddle! □ Remember that we’re in the process of performing an interactive rebase operation, and this requires Git to reapply the commits from oldest to newest at the end of the operation. Commits are listed in reverse order! The newest commit, which we would expect to appear at the top, will appear at the bottom of the list.There are two important things to keep in mind in this step: Step 3: telling Git what you want to doĪfter starting the interactive rebase session, you’ll be presented with an editor window where Git lists a series of commits - from the latest commit, all the way to (but not including) the one you picked as a base commit in Step 1. Alternatively, I also could have provided a specific SHA-1 hash. In this example, I’ve used HEAD~3 to specify the commit that’s “3 behind the HEAD commit”. We’re using the git rebase command with the -i flag (to indicate we indeed want it to be “interactive”) and provide the base commit (that we came up with in our first step above). Starting the actual session is pretty simple: $ git rebase -i HEAD~3 In this example case, we would use C1 as the starting point for our interactive rebase session. To be able to change the commit message in C2, we have to start our interactive rebase session at its parent commit (or even before that, if you want to). Our starting situation is pictured below, where we’re editing an old commit message via interactive rebase. Let’s make a practical example and say we’d like to edit an old commit message (which is what we’ll actually do in practice in a moment). The first question you need to answer is: “What part of my commit history do I want to manipulate?” This tells you where you should start your interactive rebase session. Step 1: Where should you start the session? Once you’ve firmly understood this basic mechanism, interactive rebase will lose its air of “complex mystery” and become a valuable, accessible item in your tool belt. The Basic Mechanism of an Interactive Rebase OperationĪlthough there are many different things that interactive rebase can be used for, the basic workflow is always the same. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |