3. Squashing several commits into one
Create a branch as example with multiple commits
git checkout -b squash
for c in H e l l o , ' ' w o r l d; do
echo "$c" >>squash.txt
git add squash.txt
git commit -m"Add '$c' to squash.txt"
done
How to squash commits
To squash multiple commits into one in the branch you’re on, do the following:
git log --oneline
to check how much coomits you need to squashRun
git rebase -i HEAD~4
(with 4 being the number of commits) or Rungit rebase -i [SHA]
(where[SHA]
is the commit after the last one you want to squash. *)You should see a list of commits, each commit starting with the word “pick”.
Make sure the topmost, first commit says “pick” and change the rest below from “pick” to “squash”. This will squash each commit into the previous commit, which will continue until every commit is squashed into the first commit.
Save and close the editor.
EXAMPLE
git log --oneline

git rebase -i f9781b5

Last updated
Was this helpful?