PHP Blueprint by unknow

PHP Blueprint by unknow

Author:unknow
Language: eng
Format: epub
Publisher: php[architect]
Published: 2022-08-15T00:00:00+00:00


Cleaning Up History

I use rebasing every single day to clean up the overall history before I push code up for a review. Most developers are familiar with a git history that looks like this:

// Local on our own branch 2202910e 2 days ago - Fixed phpstan errors 7eaec88b 2 days ago - Updated header to new logo 475c4c0a 3 days ago - Fixed unit tests 3c76e322 3 days ago - Typo fix f523a40d 3 days ago - Fixed bug in Service Manager cbc1eff2 4 days ago - Updated dependencies 244426b0 4 days ago - Merged branch feature/time-feature a7ec8a44 8 days ago - Added Time class a9cad80d 1 month ago - Deleted unneeded dependency on Vendor\Baz 21420248 1 month ago - Initial Commit

I have a total of six commits, from cbc1eff2 to 2202910e, including a few where I fixed a typo, then I fixed unit tests, then phpstan errors. Since I should not have misspelled that typo, and I should have run my unit tests and phpstan, I want to get rid of those commits. I do not want to get rid of work. I just get rid of the commits. At the end of the day, those commits do not provide any additional context or information about my changes.

For these types of changes, you can use an interactive rebase, called via git rebase -i <hash>. Doing so tells Git to find the starting commit of <hash> and allows us to manipulate the changes after that hash. Let’s get rid of that typo commit by combining it with f523a40d.

We kick off the rebase with:

git rebase -i cbc1eff2

We chose this commit because it is right before the first commit we want to manipulate, which is f523a40d. We do not supply f5223a40d as the hash because then we would not be able to modify it.

Git will then supply us with a list of hashes we can manipulate as well as ask us what we want to do with them:

Listing 1.

pick 2202910e Fixed phpstan errors pick 7eaec88b Updated header to new logo pick 475c4c0a Fixed unit tests pick 3c76e322 Typo fix pick f523a40d Fixed bug in Service Manager pick b2b99fb Updated dependencies # Rebase 2202910e..b2b99fb onto cbc1eff2 (6 commands) # # Commands: # p, pick <commit> = use commit # r, reword <commit> = use commit, but edit the commit message # e, edit <commit> = use commit, but stop for amending # s, squash <commit> = use commit, but meld into previous commit # f, fixup <commit> = like "squash", but discard this commit's log message

The first six lines are the commits we can manipulate. The first word of each line is a command, which the commented area at the bottom will detail. I have listed the most common five things you can do. The second column is the commit hash, and the rest of the line is the commit message. This screen allows us to queue up what we want to do and will execute it when we save and close this file.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.