Search code examples
gitgit-commit

How can I remove a commit name instead of deleting it in local machine


I have committed a piece of code as commit1 but after finishing it, I want to remove the commit1 and commit the entire code as Initial Commit.

When I run git reset HEAD~ in Git Bash, it results in deleting all my code.

Is it possible to delete commit1 instead of everything, and how?


Solution

  • Yes. You can for example run:

    git rebase --interactive --root
    

    And then change the action before the commit you want to squash to f (it stands for fixup = squash the commit to the previous one and discard the commit message). Then simply save and close the file (using :wq if it opened the default Vim editor).