[Solved] How to squash the number of commits from a branch in Git
Git commit is the safer side to protect our work from system crash so like everyone I am also doing git commits multiple times. Then I have a question, here you doing lot of commit does it make any blocker ?
Answer is "No".
Then why are we required to squash ?
During development time we will do a lot of commits until the work is getting done. After completion of the work or review time you may experience the below.
-
You can see a lot of commits mixing the appearance of important and non-relevant commits. That may feel looks ugly.
-
In some projects the commit message has validation to build the current branch. For example, a commit message must include common syntax if didn't have then the build will be cancelled. In this situation we have to clear the previous history by doing the git squash.
Then git squash only the solution to resolve the situation, it has been done by executing the a command called git reset
. Yes, this command will help us to squash git commits.
This operation is a bit tricky, so we should have more attention when doing this activity.
Can we squash the commits from a branch ?
We have a situation to clear the unwanted commits details into the commit history, if we having lot of commits that look very ugly and will face lot of problems when doing other git operations such as git reset.
What is git squash ?
Combine multiple commits into one commit.
There are other commands also available but I am using a different approach.
To do this operation follow the below git commands,
Get the number of commits to the git branch using the below command
To achieve this operation, the most relevant detail is the number of commits you have made.So get the number of commit as given below.
git rev-list --count HEAD ^<branch-name>
E.g:- git rev-list --count HEAD ^feature/update-heading-in-form
The above command will return the number of commits. Consider the number of commit is 7 (7 for DHONI :) ).
If you did not provide the branch name
, then the command will return the number of commits to the repository.The upcoming steps are very important and we have to execute it carefully.
Okay ?,
Then, by using this number, we want to execute another git squash command.
Please checkout your branch and do the below git command
git reset --soft HEAD~7
The above git command pulls all the commit history. Please fix it if any conflicts are there. Finally, push the changes into force mode.
git push --force
-
Git squash commit in short steps,
git rev-list --count HEAD ^< branch-name >
Step-2. If the commit count is 7 then,
git reset --soft HEAD~7
Step-3. Fix the conflicts if any!
Step-4. Push back to git in force mode
git push --force
More Stories
Cross-Origin Resource Sharing (CORS) is a security feature that lets a web page from one domain request resources from a different domain
SVG elements will not add the accessibility atttributes by default, so that will fail to describe by itself, and the NVDA and other screen reader required these attributes to work.
Despite being acquainted with git, many developers struggle to resolve these conflicts due to a lack of understanding of how to pull the conflict details into their local machines.
Firebase Authentication is one of its gems, allowing you to add user authentication effortlessly. It's secure, reliable, and comes with Google's seal of approval.
Why am I getting an auth/invalid-api-key error when setting the Firebase values in the environment variable on NextJS ?
Enzyme Internal Error: Enzyme expects an adapter to be configured, but found none.
Easist way of downloading the SVG file as PNG file is done using javascript snippet
To keep the code is safe and distrubuted between multiple resources that been achieved with the help of GIT
The importance of the http response headers are highly needed to protect the websites from hackers. If you poorly managed the response header then one day the website will be compromise to the hacker.
An HTTP header is a response by a web server to a browser that is trying to access a web page.
Application Insights is an feature of Azure Monitor and it provides application performance monitoring features. APM tools are very useful to analyse applications from development, testing and production release.
A lazy function lets you defer the loading of a components code until it is rendered for the first time. Before, it will remain in the bundle. So that we can reduce the load of the application.
We covered most asked questions for Javascript interview and their answers
we are displaying these emojis with the help of ASCII code and it is not that easy to remember because its a mix of numeric and special characters.
ES6 or the ECMAScript 2015 is the major edition of ECMAScript language, it introduced several new features which are very special to the developers
what are the new features among the various versions of ECMA script and what is difference
Your focus-trap must have at least one container with at least one tabbable node in it at all times, when using dialog or modal in ReactJS or other front-end framework
Writing test cases for modal popup in jest
Cannot read property location of undefined, this is an common test cases error in react jest while using useLocation hook in your react component
There is a common problem when parsing the markdown file the ID attribute is missing in the element, here we found a solution to fix/overcome
It is basicall demonstrating how to find the fibanocci, amstrong, prime numbers and pyramid pattern using javascript.
Markdown is a lightweight markup language that you can use to add formatting elements to plaintext text documents.
There are few development tips for Javascript array operation, these tips will reduce your development time.
For every website the Sitemap will be playing important role for SEO performance. In Ecommerce and other consumer websites also SEO have important role for developing their revenue.
This question is very usual, to get solve this issue by using the browser property user agent to check whether the device type.
What are the possible ways to create objects in JavaScript, The traditional way to create an empty object is using the Object constructor. But currently this approach is not recommended.