-3

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?

Pure.Krome
  • 84,693
  • 113
  • 396
  • 647
  • 1
    Does this answer your question? [How can I merge multiple commits onto another branch as a single squashed commit?](https://stackoverflow.com/questions/5308816/how-can-i-merge-multiple-commits-onto-another-branch-as-a-single-squashed-commit) – kosist Aug 05 '22 at 09:32

1 Answers1

2

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
eftshift0
  • 26,375
  • 3
  • 36
  • 60