![]() ![]() The question is why do you need something like this? So normally when you develop some feature you created a feature branch from master and are working there. So what is squash in git? It's a process when you take several commits and make single commit from them. Just to sum up the previous video - always use merge and not rebase because it's save and do are not override git history. So if you didn't see my video "Differences between merge and rebase" I highly recommend to check if first. ![]() So squashing commit goes a lot in direction of differences between merge and rebase. When you run git reflog, this is what you see.In this video I want to talk about one useful git feature which is squashing commits. Basically every action you perform inside of Git where data is stored, you can find it inside of the reflog. This command is to manage the information recorded in it. Reflog is a mechanism to record when the tip of branches are updated. So, it maintains a history of all the actions that you do inside your Git. Git has it into consideration already that “You will make mistake”. Whenever you make changes to your branch, git records it. However, there is no direct way to un-squashing the commits in Git.Īfter 30 minutes of struggle, I reached out to one of my colleague about the problem and he suggested me a life-saving command – It’s time-consuming, repetitive and boring. Because the head of the branch will no longer be in sync with the remote. And on top of that, it would create a mess for all the team members. I will have to force push it to put it there. The concern was, I changed the master commit. And if you are working on a large codebase, you know how hard it is to resolve the conflicts. Not only that, but I also got a lot of conflicts in the codebase. Laugh all you want, but it can happen to you too. Now, the master commit itself was changed and all my changes were in it. But what actually happened was that I merged the commits with the master. So, there was a master commit and then there were my commits (on top of the master). ![]() And when I squashed the commits, I squashed them with the wrong one. There were more than 25 commits in the code. There were a lot of small careful changes that I made. I was working on a project’s code for 2 days. Now, that you got the idea, let’s see where I made a mistake and why I had to undo the squash. ![]() I wrote a little example for you to follow. Let me explain “Git Squash” quickly for those who have not heard of it.Īs the name suggests, Git Squash is basically squashing multiple commits into one. I frequently use Git Squash to make commits clean.īut sometimes… Things don’t go your way □ Git Squash That is why I squash the commits with a relevant message stating “What I Did” and in the description “Why I Did It” before pushing it to the master. But when the team size is big or there are multiple teams working on the same codebase then its really important that you maintain a clean commit history that clearly explains what is happening there. It is super okay when you are working alone or in a small team. Some of these commits are a single line change. One downside of it is that you will have a lot of commits in your branch. I personally recommend “Quick Commits” to everyone. This way helps me to get back to the earlier version without losing much work. Also, I have got a habit of making quick, short commits while I’m working locally. I like my commits to be clean and understandable. We tend to become careless in tasks that we do on a regular basis. Usually, it happens right after when you do something silly, and it costs you hours of re-work. That moment is a classic moment in every developer’s life. There will be times when you will realize “Oh, no! What’ve I done?”. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |