Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (29.3k points)

I make a new branch from the master with:

git checkout -b testbranch

I make 20 commits into it.

Now I want to squash those 20 commits. I do that with:

git rebase -i HEAD~20

What about if I don't know how many commits? Is there any way to do something like:

git rebase -i all on this branch

1 Answer

0 votes
by (50.2k points)

To squash all your commits and to reset the index to master:

 git checkout yourBranch

 git reset $(git merge-base master yourBranch)

 git add -A

 git commit -m "one commit on yourBranch"

Note: finding that origin branch isn't easy/possible with Git.

but the above method is not a perfect one because it has a list, where the branch is coming.

so there is a way for that you will need to use:

 git push --force

For the reset, you can do

git reset $(git merge-base master $(git rev-parse --abbrev-ref HEAD)) 

it automatically uses the branch you are currently on.

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.5k questions

32.6k answers


108k users

Browse Categories