pba-content
pba-content copied to clipboard
Define flow for applying patches with divergent git histories
We on occasion need to issue a patch to a classroom assignment, but sadly each new template repo derived for every student has a random init commit hash, and thus git apply workflows do not work. (related to #357 )
patch : (man page) seems to be the tooling we need to get around this: see this post & a little demo.
- [ ] Define a diff & patch with divergent git history workflow in a how-to for instructors
- [ ] Template message to send out to those needing to apply the patch (this can include the actual body of the patch! or as an attachment)
- [ ] Reference this new guide in exercises & assignments and the https://github.com/Polkadot-Blockchain-Academy/Rust-Entrance-Exam where this pattern is important.
I just had a mind blow moment. I learned about git merge --allow-unrelated-histories. This might be the thing that finally stops me bitching about github classroom not preserving history.
--allow-unrelated-histories. turned out to be a red herring.
Rather, patch is nice!
# instructor with changes on some branch (could be commits diff too)
git diff main fixes-branch > assignment-X-patch.diff
# Send diff file to students
# students run
patch -p1 < assignment-X-patch.diff
# students review file changes, stage, and commit
Assumes students have same file structure and maybe close-sh line numbers. If this patch is not working, try making a diff with more lines of context
# 100 lines of context around lines changed
git diff -U100 branch1 branch2 > assignment-X-patch.diff
damn. Many could not do this patch, with anything added to the original file. Some one gymnastics are needed
https://git-scm.com/docs/git-apply might be a better option. :shrug: will try more things latter on
--allow-unrelated-histories. turned out to be a red herring.
What made you conclude this?
Any variation of this I tried was more than a one liner like patch (I thought) was, and every one was a full file diff there was only all or nothing for and changes at all.