Last active
September 26, 2024 01:42
-
-
Save kilip/e333952c30a73f077a868da7c3859c4e to your computer and use it in GitHub Desktop.
Revisions
-
kilip revised this gist
Sep 26, 2024 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,7 @@ --- ## Git Merge Commits Tutorial In this tutorial we will merge several commits into one single commit ### 1. Change to Your Working Directory -
kilip revised this gist
Sep 26, 2024 . 1 changed file with 46 additions and 19 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,42 +1,60 @@ --- ## Git Merge Commits Tutorial ### 1. Change to Your Working Directory Navigate to your project directory: ```sh cd path/to/project ``` ### 2. List Your Commits View the commit history in a concise format: ```sh git log --oneline ``` This command will display output like: ``` d5eb363 (HEAD) wip 323b361 wip 066d50c wip f056912 feat(strapi-bridge): integrated openapi-fetch :rocket: defad49 (upstream/main, origin/main, origin/HEAD, main) Merge pull request #13 from kilip/strapi ``` ### 3. Count Commits to Merge Identify how many commits you want to merge starting from `(HEAD)`. For instance, if you wish to merge from `feat(strapi-bridge)` to `(HEAD) wip`, count the commits, which in this example would be **4**. ### 4. Start the Rebase Initiate an interactive rebase with the following command: ```sh git rebase -i HEAD~4 ``` This opens your Git editor, displaying something like: ``` pick f056912 feat(strapi-bridge): integrated openapi-fetch :rocket: pick 24a1c6b wip pick 8816256 wip pick b0aa58b wip # Rebase defad49..d5eb363 onto defad49 (4 commands) ``` ### 5. Modify the Commit Commands Change `pick` to `s` (squash) for the commits you want to combine: ```sh pick f056912 feat(strapi-bridge): integrated openapi-fetch :rocket: s 24a1c6b wip @@ -45,8 +63,12 @@ s b0aa58b wip # Rebase defad49..d5eb363 onto defad49 (4 commands) ``` ### 6. Save Changes After saving, your editor will show a message like this: ``` # This is a combination of 4 commits. # This is the 1st commit message: feat(strapi-bridge): integrated openapi-fetch :rocket: @@ -59,20 +81,25 @@ wip # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. ``` ### 7. Edit the Commit Message Decide whether to keep or remove the commit messages. For example, to remove all `wip` messages, you would edit it to: ``` # This is a combination of 4 commits. # This is the 1st commit message: feat(strapi-bridge): integrated openapi-fetch :rocket: # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. ``` ### 8. Finalize and Push Changes Save your changes and force push your commits to the remote repository: ```sh git push origin main --force ``` -
kilip created this gist
Sep 26, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,78 @@ Change to your working directory ```sh cd path/to/project ``` list your commit: ```sh git log --oneline ``` this will display output like: ```sh d5eb363 (HEAD) wip 323b361 wip 066d50c wip f056912 feat(strapi-bridge): integrated openapi-fetch :rocket: defad49 (upstream/main, origin/main, origin/HEAD, main) Merge pull request #13 from kilip/strapi ``` Count the commits you want to merge from `(HEAD)` commit. For example, if we want to merge commit from commit from `feat(strapi-bridge)` to `(HEAD) wip` then the count should be **4**. start rebase by using ```git rebase -i HEAD~4``` where 4 is commit count in the example above: ```sh git rebase -i HEAD~4 ``` This command will opening your git editor, with output like this: ```sh pick f056912 feat(strapi-bridge): integrated openapi-fetch :rocket: pick 24a1c6b wip pick 8816256 wip pick b0aa58b wip # Rebase defad49..d5eb363 onto defad49 (4 commands) .... ``` Change ```pick``` to ```s``` (squash): ```sh pick f056912 feat(strapi-bridge): integrated openapi-fetch :rocket: s 24a1c6b wip s 8816256 wip s b0aa58b wip # Rebase defad49..d5eb363 onto defad49 (4 commands) ``` Save your changes which will open your git editor with output like this: ```sh # This is a combination of 4 commits. # This is the 1st commit message: feat(strapi-bridge): integrated openapi-fetch :rocket: # This is the commit message #2: wip # This is the commit message #3: wip # This is the commit message #4: wip # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. ...etc ``` Remove or keep the commit message, for example if I want to remove all wip message: ```sh # This is a combination of 4 commits. # This is the 1st commit message: feat(strapi-bridge): integrated openapi-fetch :rocket: # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. ...etc ``` Save your changes, and **force push** your commits to remote repository: ```sh git push origin main --force ```