I have made 2 'git commit' locally. But I have not pushed, is it possible for me to edit my git and combine those 2 git commit into 1?
To merge branches locally, use git checkout to switch to the branch you want to merge into. This branch is typically the main branch. Next, use git merge and specify the name of the other branch to bring into this branch. This example merges the jeff/feature1 branch into the main branch.
You can choose to squash merge when completing a pull request in Azure Repos. Choose Squash commit under Merge type in the Complete pull request dialog to squash merge the topic branch.
Yes it is possible:
You have to first find the commit that is before the ones you want to work with. Imagine we want to combine last two commits:
git rebase -i HEAD~3
This will fire up an editor for interactive rebase that is giving you a possibility to perform so called squashing of the commits and it will list commits starting from one that is three commits ago.
PLEASE, read the help message in the fired up editor window to understand how to use interactive rebase. In order to cancel rebase operation you have to delete all lines from the file and save it ! You also don't touch the commit ID and description - you just change the command before the commit ID from pick to "s" (squash)
Another thing is that you absolutely correctly mentioned that you didn't push yet. First and only one rule of git is "Do not rewrite published history". I.e. you don't rebase, reorder or delete commits that were already pushed for public access. This is true for all situation except when you're the only one who works on the project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With