pcottle / learnGitBranching

An interactive git visualization and tutorial. Aspiring students of git can use this app to educate and challenge themselves towards mastery of git!
https://pcottle.github.io/learnGitBranching/
MIT License
30.4k stars 5.74k forks source link

Add support for `git merge --squash {branch}` #1035

Closed gatsbimantico closed 1 year ago

gatsbimantico commented 1 year ago

Being a popular option in Github to squash and merge, it would be interesting to add support for this option.

Initial scenario After running git checkout -b feat;git commit;git checkout main;

C2 (feat)
C1 (main) *

With merge --no-ff After running git merge --no-ff feat

C2 (feat) ─┐
C1 ────────┴─ C3 (main) *

With merge --squash After running git merge --squash feat

C2 (feat)
C1 ────────── C3 (main) *

This equivalent to just git commit -m "Squashed merge branch 'feat' into 'main'" as the connection with the C2 node is lost, and further git branch -D feat will leave C2 being not connected and ready to prune. This will show how you destroy history by using squash.

netlify[bot] commented 1 year ago

Deploy Preview for xenodochial-hugle-b9ec84 ready!

Name Link
Latest commit 30a50cf4c027a5c75a7a1e07d66d18956dc29cf9
Latest deploy log https://app.netlify.com/sites/xenodochial-hugle-b9ec84/deploys/6386c18ad546a70009ee918b
Deploy Preview https://deploy-preview-1035--xenodochial-hugle-b9ec84.netlify.app/
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

pcottle commented 1 year ago

Wow really awesome that you put up the functionality yourself! And figured out the somewhat gross/obtuse ways we parse command options and pass them around 🥴

Thanks a bunch for the test as well!

pcottle commented 1 year ago

(it's still in draft but ready to merge it whenever, unless you also want to add a lesson slide for it)

gatsbimantico commented 1 year ago

Hello @pcottle Thank you for this app ❤️ The code was really easy to follow, it's very clean.

I was just manually testing it now. While we can do git merge --no-ff side it seems to need two arguments for squash git merge --squash main side So I'll try to fix that.

I don't feel like I can put together a lesson for it. I guess it will be an initial state with a couple of branches, and a final state with just main, so you have to use merge --squash to merge to main, then branch -D some-branch to remove references and gc to prune the tree. Do you want to give it a go?

pcottle commented 1 year ago

yeah I can try to add a lesson once this lands (if folks are interested)

gatsbimantico commented 1 year ago

Thank you, that change worked. Now I understand why the value of the first argument seemed to not be used.

There's something funny with the tests, it might be related to the depth of the objects being compared. Also the error messages are not helpful because the assertion is just testing for truthy.

But I think this improvement is ready to go 🎉

pcottle commented 1 year ago

Awesome! this looks ready to go, I'll merge and push the site now

Also the error messages are not helpful because the assertion is just testing for truthy.

Yeah unfortunately it's just checking if the tree is in the expected state; theres no helpful debug message if that assertion is incorrect :/

pcottle commented 1 year ago

It's live! https://learngitbranching.js.org/?NODEMO&command=gc;%20git%20checkout%20-b%20side%20C1;%20git%20commit;%20git%20switch%20main;%20git%20merge%20side%20--squash