I'm trying to find out if it's possible to merge all commits for a custom branch, after the branch was created?
At some point, I created a branch called some-branch
off main
. I did about 90 commits. Now, is there a way I can merge all of those commits? Problem is, I'm not sure if I pulled anything down from main
-during- my development of those 90 commits.
It's like I want to see -my- changes and not the other stuff? is this possible?
CodePudding user response:
If you are unsure if you merged, then it's good to first find out the last common ancestor. This works if you merged or not:
git checkout my-branch
git reset --soft $( git merge-base HEAD the-main-branch )
git commit -m "All my changes in a single shot"
That should work.
Another way should be:
git checkout $( git merge-base HEAD the-main-branch )
git restore --worktree --staged --source=my-branch .
git commit -m "All my changes in a single shot"
# if it's all correct:
git branch -f my-branch # set my-branch over here
git checkout my-branch