Skip to main content

How to combine the last two commits into a single one in Git

 How to combine the last two commits into a single one in Git


If you want to squash the last two commits into one without changing the commit message, you can follow these steps:

Steps to Squash the Last Two Commits Without Changing the Commit Message


  1. Start an Interactive Rebase: Use the git rebase -i command to start an interactive rebase for the last two commits: 

    git rebase -i HEAD~2


  2. Edit the Rebase File: In the text editor that opens, you’ll see something like this:

    pick a1b2c3 First commit message
    pick d4e5f6 Second commit message

    Change the second pick to squash (or s) to indicate you want to squash it into the first commit:

    pick a1b2c3 First commit message
    squash d4e5f6 Second commit message


  3. Save and Close the Editor: After making the change, save and close the editor.


  4. Keep the Commit Message: When Git opens another editor for the commit message, it will show you both commit messages. You can simply delete the second commit message and leave the first one as is, or you can keep both messages without any modifications. If you want to keep the first commit message exactly as is, just make sure it appears correctly.

    For example, it might look like this:

    First commit message


  5. Save and Close the Editor Again: Save and close the editor again to complete the rebase.


  6. Force Push (if applicable): If you had previously pushed the original commits to the remote repository, you will need to force push the changes:

    git push origin HEAD --force




Comments

Popular posts from this blog

Use CS50 Library in Your Local Machine Offline (C Language Setup)

Use CS50 Library in Your Local Machine Offline (C Language Setup) Make Your PC Ready for C Programming with CS50 In this guide, you will learn how to prepare your computer to run C programs locally and use the CS50 library offline. The following videos will walk you through all required tools and setup steps. Step 1: Install Visual Studio Code This video explains how to download and install Visual Studio Code on Windows 10. Step 2: Install C/C++ Compiler (GCC, G++, GDB) Learn how to install the C/C++ toolchain using MinGW-w64 and MSYS2. Step 3: Configure VS Code for C/C++ This step shows how to properly configure Visual Studio Code for C and C++ programming. How to Use CS50 Library Offline After completing the setup above, follow these steps to use the CS50 library locally without internet access: Download the CS50 library from GitHub Releases: https://github.com/cs50/libcs50/rel...

Install Windows 11 on a bootable USB using Linux

 Install Windows 11 on a bootable USB using Linux 1 Download the iso image of Windows from the offical website for Microsoft 2 Open terminal and run these commands to install WoeUSB sudo add-apt-repository ppa:tomtomtom/woeusb sudo apt update sudo apt install woeusb 3 Plugin the USB into the device, and run this command lsblk Assume your USB is /dev/sdb 4 Format it to NTFS or FAT32: sudo mkfs.ntfs -f /dev/sdb # or sudo mkfs.vfat -F 32 /dev/sdb 5 Unmount the USB sudo umount /dev/sdb* 6 Burn the ISO file into the USB sudo woeusb --device /path/to/windows.iso /dev/sdb 7 Remove the USB if the files are burned successfuly and it can be used as bootable to install Windows.