📜  git squash commit - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:00:56.698000             🧑  作者: Mango

Git Squash Commit

As programmers, we often have to make several small commits while working on a feature or fixing a bug. However, when it comes to merging those changes into the main branch, it is often better to have a clean and concise commit history. This is where Git Squash Commit comes in handy.

What is Git Squash Commit?

Git Squash Commit is a feature in Git that allows you to combine multiple small commits into a single, more concise commit. This makes it easier to manage the commit history and keep it clean and organized.

How to use Git Squash Commit

To use Git Squash Commit, follow the steps below:

  1. Check out the branch you want to squash the commits into:
$ git checkout my-branch
  1. Use the interactive rebase feature with the "squash" option:
$ git rebase -i HEAD~n

Where "n" is the number of commits you want to squash. This will open up an editor with a list of the commits you are about to squash.

  1. Replace the word "pick" with "squash" for the commits you want to squash:
pick abc123 Commit message 1
squash def456 Commit message 2
squash ghi789 Commit message 3
  1. Save the file and exit the editor. This will combine the three commits into one and prompt you to enter a new commit message for the squash commit.

  2. Save the new commit message and exit the editor. The squash commit will now be added to the branch and the commit history will be clean and concise.

Conclusion

By using Git Squash Commit, you can easily manage your commit history and keep it clean and organized. This is especially useful when working on a large project with many contributors. So next time you need to merge changes into the main branch, don't forget to use Git Squash Commit!