If I have commit A
tagged with tag e.g. tag-A
, and then the next commit B
tagged with tag-B
; if I squash these 2 commits what happens to the tags? Will both be assigned to the squashed commit?
Squashing is a way to rewrite your commit history; this action helps to clean up and simplify your commit history before sharing your work with team members. Squashing a commit in Git means that you are taking the changes from one commit and adding them to the Parent Commit.
Even when a commit is squashed , it's still recoverable as the data is in the commit history. Once you know the SHA of the blob you want to recover, use: $ git cat-file -p <SHA> > recover_file.
Specifically, squashing throws away all our hard work in building a specific commit graph. Instead, squashing takes all the changes and squashes them together into a single commit. It's as if you made all the changes at one sitting and committed them as a unit.
As a general rule, when merging a pull request from a feature branch with a messy commit history, you should squash your commits. There are exceptions, but in most cases, squashing results in a cleaner Git history that's easier for the team to read.
The tags won't move because a rebase rewrites history. The original commits will have the tags since tags don't move. Here's a picture:
Before:
(HEAD) B - tag-B
|
A - tag-A
|
X
After:
B - tag-B
|
(HEAD) C A - tag-A
|/
X
Here C
is the squash of A
and B
. It starts a completely new history, in which A
and B
will not participate. The branch head will move over to C
and will proceed from there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With