Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens to tags of squashed commits?

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?

like image 305
Jim Avatar asked Jan 20 '19 21:01

Jim


People also ask

What happens when you squash a 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.

Can you recover squashed commits?

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.

What happens if you squash a merge commit?

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.

Is squashing commits a good idea?

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.


1 Answers

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.

like image 108
Mad Physicist Avatar answered Oct 03 '22 00:10

Mad Physicist