1/21/2024 0 Comments Git rebase to commit![]() To have these changes take effect we save and quit our text editor (in VIM we press esc + :x (or :wq). Our edits are telling git to combine commits 2efcabb and those before it into commit 5c04e31, the most previous commit that has not been squashed. In our case, we want to squash or s a bunch of commits, so we change the file to this:Īll of those ses on the left hand side mean (as it says in the comments below) “meld into previous commit”. The text at the bottom explains what you can do to the commits, as well as how to bail out and leave everything untouched (delete all the lines in the file, save, and quit). This shows us we would have been fine going back 12 commits. The earliest commit we want to keep is 5c04e31, second from the top. For us, the unmodified document looked like: This brings up a document in your terminal editor that you will modify to control what the rebase does. In our case we need to go around 13 commits back from the HEAD, which translates to the command: That is, how many commits back from the HEAD do you need to go? It’s fine (but unnecessary) to go father back than you need, but if you don’t go far enough back you will not be able to modify the commit. Given that git rebase -interactive is editing the history, you will need to know how much of the history you want to edit. For example, if one commit fixes the indentation of line 166 and another commit fixes the indentation of line 167, it is very hard to think of why these commits should be separate. When squashing (or fixing up) commits you will lose history, so you should be sure the history you are overwriting is not meaningful to the story of your code. This is not something to do without a bit of reflection. They would therefore be better represented (and easier to understand) if we record them in a single commit. There’s no good reason for these changes to each be recorded in a separate commit, they all represent part of the same improvement: to pass the formatting and static analysis checks. In our specific use case, we have a bunch of single commits involving small changes to code formatting that we made to satisfy the formatting and static analysis checks our CI tool runs. Here we will talk about using it to “squash” (as in combine, merge, or meld) multiple commits into a single commit. ![]() You might want to edit a commit message, delete commits, reorder commits, or edit commits. There are plenty of reasons to get familiar with and start using git’s interactive rebase.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |