I squashed a branch with a very large amount of commits (+1000) to my main branch accidentally. After that, some commits were made to some of those commits files. Now, I'd like to "unsquash" those +1000 commits.
Any ideas about how can I unsquash those commits without losing the commits made over them?
I tried reset --hard my main branch to before the squash and merge again the branch with the +1000 commits, but it didn't work because I lost the commits made after the squash. Also, if I merge main again, the squash commit would still exists and will "cover" the other commits in Git Blame
Before the squash, your repo looked like this:
After the squash, it looked like this...
...assuming you did not delete the branch.
Assuming you mean that you added commits to main, your repo now looks like this:
Yes, do an interactive rebase and remove the squash commit.
Pick a commit before the squash, and then start an interactive rebase:
git rebase -i <commit>. An editor will appear with all the commits after your chosen one. Simply delete the line with the squash, save, and exit the editor. Git will rewrite the commits after the squash (G - H) on top of the previous commit (F). See Rewriting History for more detail on interactive commit.Then, if you already pushed main,
git push --force-with-leaseto safely push the new branch.UPDATE Comments from the OP have made it clear the situation is much more complex.
A branch with over 1000 commits indicates something is wrong, or very exceptional, with your process, and I encourage you to ask a question about that process.
Your repo looks something like this. I've only shown two squashes and two merges for simplicity.
You want this.
You can do this with a rebase, being careful to preserve the merges.
Where "S2" is the last squash merge you wish to delete.
-rtells Git to preserve merge commits. This should work, but be prepared to undo it withgit reset --hard ORIG_HEAD. See Rebasing Merges for more.