0 votes
1 view
in Devops and Agile by (29.1k 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 (49.6k 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 !


Categories

...