Skip to content

Instantly share code, notes, and snippets.

@diegopacheco
Last active March 9, 2021 20:17
Show Gist options
  • Save diegopacheco/f9392bada054b87a7be5641d26a02391 to your computer and use it in GitHub Desktop.
Save diegopacheco/f9392bada054b87a7be5641d26a02391 to your computer and use it in GitHub Desktop.
Git Rebase & Squash

Figure out the commit range

git log

Squash and edit commit message

###
### Commit RANGE from Older to Newer
###        OLDER commit                             NEW COMMIT 
git rebase 1483870be2e905111234c4a9ce654c3108dcfdbc b9f14b69ba7f62dd6bbcbb986dc0de75a643b14a -i

You will see something like this:

pick fbb89b1 This is a dummy message
pick fbb89b2 This is a dummy message
pick fbb89b3 .
pick fbb89b4 .

Change it to be all "s"(squash) but the first commit "p"(pick):

p fbb89b1 This is a dummy message
s fbb89b2 This is a dummy message
s fbb89b3 .
s fbb89b4 .

Them you will write a commit message:

ARCH-12345: This is a git commit POC 

Shortcut: Get all commits - including the first one

git rebase -i --root
You will see something like this:
```bash
pick fbb89b1 This is a dummy message
pick fbb89b2 This is a dummy message
pick fbb89b3 .
pick fbb89b4 .

Change it to be all "s"(squash) but the first commit "p"(pick):

p fbb89b1 This is a dummy message
s fbb89b2 This is a dummy message
s fbb89b3 .
s fbb89b4 .

Them you will write a commit message:

ARCH-12345: This is a git commit POC 

Origin and our branch out of sync? issues to push to remote? do this!

git push origin -f

Oops - How do I cancel?

git rebase --abort
@diegopacheco
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment